aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/coarse__mesh__build_8cpp-source.html
blob: f738f6a92c44b454b6ee7154500f0fbbc143d787 (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
<!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=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="/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>coarse_mesh_build.cpp</h1><a href="coarse__mesh__build_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2001 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="coarse__mesh__build_8h.html">3d/coarse_mesh_build.h</a>"</font>
00029 
00030 <font class="preprocessor">#include "<a class="code" href="mesh_8h.html">3d/mesh.h</a>"</font>
00031 
00032 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00033 
00034 <font class="keyword">namespace </font>NL3D 
00035 {
00036 
00037 <font class="comment">// ***************************************************************************</font>
00038 
<a name="l00039"></a><a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#a0">00039</a> <font class="keywordtype">bool</font> CCoarseMeshBuild::build (<font class="keyword">const</font> std::vector&lt;CCoarseMeshDesc&gt;&amp; coarseMeshes, CBitmap&amp; bitmap, CStats&amp; stats, <font class="keywordtype">float</font> mulArea)
00040 {
00041         <font class="comment">// 1. build the bitmap</font>
00042         <a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#u0">MapBitmapDesc</a> desc;
00043         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#c1">buildBitmap</a> (coarseMeshes, bitmap, stats, desc, mulArea)==<font class="keyword">false</font>)
00044                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00045 
00046         <font class="comment">// 2. remap coordinates</font>
00047         <a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#c2">remapCoordinates</a> (coarseMeshes, desc);
00048 
00049         <font class="comment">// 3. ok</font>
00050         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00051 }
00052 
00053 <font class="comment">// ***************************************************************************</font>
00054 
00055 <font class="comment">// Class descriptor for bitmap inserted</font>
<a name="l00056"></a><a class="code" href="classNL3D_1_1CInsertedBitmap.html">00056</a> <font class="keyword">class </font>CInsertedBitmap
00057 {
00058 <font class="keyword">public</font>:
00059         <font class="comment">// Width and height</font>
<a name="l00060"></a><a class="code" href="classNL3D_1_1CInsertedBitmap.html#m0">00060</a>         uint <a class="code" href="classNL3D_1_1CInsertedBitmap.html#m0">Width</a>;
<a name="l00061"></a><a class="code" href="classNL3D_1_1CInsertedBitmap.html#m1">00061</a>         uint <a class="code" href="classNL3D_1_1CInsertedBitmap.html#m1">Height</a>;
00062 
00063         <font class="comment">// Coordinates</font>
<a name="l00064"></a><a class="code" href="classNL3D_1_1CInsertedBitmap.html#m2">00064</a>         uint <a class="code" href="classNL3D_1_1CInsertedBitmap.html#m2">U</a>;
<a name="l00065"></a><a class="code" href="classNL3D_1_1CInsertedBitmap.html#m3">00065</a>         uint <a class="code" href="classNL3D_1_1CInsertedBitmap.html#m3">V</a>;
00066 };
00067 
00068 <font class="comment">// ***************************************************************************</font>
00069 
<a name="l00070"></a><a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#c1">00070</a> <font class="keywordtype">bool</font> CCoarseMeshBuild::buildBitmap (<font class="keyword">const</font> std::vector&lt;CCoarseMeshDesc&gt;&amp; coarseMeshes, CBitmap&amp; bitmap, CStats&amp; stats, MapBitmapDesc&amp; desc, <font class="keywordtype">float</font> mulArea)
00071 {
00072         <font class="comment">// Total area used by texture</font>
00073         uint totalArea=0;
00074 
00075         <font class="comment">// ***************************************************************************</font>
00076 
00077         <font class="comment">// 1. scan each bitmap: calc the area of the bitmap and it its name in the maps sorted by area</font>
00078         <font class="keyword">typedef</font> std::multimap&lt;uint, CBitmapDesc&gt; MapAreaBitmap;
00079         MapAreaBitmap mapArea;
00080         uint mesh;
00081         <font class="keywordflow">for</font> (mesh=0; mesh&lt;coarseMeshes.size(); mesh++)
00082         {
00083                 <font class="comment">// Geom mesh pointer</font>
00084                 CMeshGeom *meshGeom=coarseMeshes[mesh].MeshGeom;
00085 
00086                 <font class="comment">// Base mesh pointer</font>
00087                 <font class="keyword">const</font> CMeshBase *meshBase=coarseMeshes[mesh].MeshBase;
00088 
00089                 <font class="comment">// For each matrix block</font>
00090                 uint matrixBlock;
00091                 uint nbMatrixBlock=meshGeom-&gt;getNbMatrixBlock();
00092                 <font class="keywordflow">for</font> (matrixBlock=0; matrixBlock&lt;nbMatrixBlock; matrixBlock++)
00093                 {
00094                         <font class="comment">// For each render pass</font>
00095                         uint renderPass;
00096                         uint numRenderPass=meshGeom-&gt;getNbRdrPass(matrixBlock);
00097                         <font class="keywordflow">for</font> (renderPass=0; renderPass&lt;numRenderPass; renderPass++)
00098                         {
00099                                 <font class="comment">// Render pass material</font>
00100                                 uint32 matId=meshGeom-&gt;getRdrPassMaterial(matrixBlock, renderPass);
00101 
00102                                 <font class="comment">// Checks</font>
00103                                 <a class="code" href="debug_8h.html#a6">nlassert</a> (matId&lt;meshBase-&gt;getNbMaterial());
00104 
00105                                 <font class="comment">// Get the material</font>
00106                                 <font class="keyword">const</font> CMaterial &amp;material=meshBase-&gt;getMaterial(matId);
00107 
00108                                 <font class="comment">// Get the texture</font>
00109                                 ITexture *texture=material.getTexture(0);
00110                                 <font class="keywordflow">if</font> (texture)
00111                                 {
00112                                         <font class="comment">// Get its name</font>
00113                                         std::string name;
00114                                         <font class="keywordflow">if</font> (texture-&gt;supportSharing())
00115                                         {
00116                                                 <font class="comment">// Get sharing name</font>
00117                                                 name=texture-&gt;getShareName();
00118                                         }
00119                                         <font class="keywordflow">else</font>
00120                                         {
00121                                                 <font class="comment">// Build a name</font>
00122                                                 name=toString ((uint)texture);
00123                                         }
00124 
00125                                         <font class="comment">// Already added ?</font>
00126                                         <font class="keywordflow">if</font> (desc.find (name)==desc.end())
00127                                         {
00128                                                 <font class="comment">// Add it..</font>
00129 
00130                                                 <font class="comment">// Generate the texture</font>
00131                                                 texture-&gt;generate();
00132 
00133                                                 <font class="comment">// Convert to RGBA</font>
00134                                                 texture-&gt;convertToType (CBitmap::RGBA);
00135 
00136                                                 <font class="comment">// Backup original size</font>
00137                                                 <font class="keywordtype">float</font> originalWidth = (float)texture-&gt;getWidth();
00138                                                 <font class="keywordtype">float</font> originalHeight = (float)texture-&gt;getHeight();
00139 
00140                                                 <font class="comment">// Expand the texture</font>
00141                                                 <a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#c0">expand</a> (*texture);
00142 
00143                                                 <font class="comment">// Descriptor for this texture</font>
00144                                                 CBitmapDesc descBitmap;
00145                                                 uint area = texture-&gt;getWidth() * texture-&gt;getHeight();
00146                                                 descBitmap.Texture = texture;
00147                                                 descBitmap.Name = name;
00148                                                 descBitmap.FactorU = originalWidth;
00149                                                 descBitmap.FactorV = originalHeight;
00150 
00151                                                 <font class="comment">// Insert it in the maps</font>
00152                                                 desc.insert (MapBitmapDesc::value_type (name, descBitmap));
00153                                                 mapArea.insert (MapAreaBitmap::value_type(area, descBitmap));
00154 
00155                                                 <font class="comment">// Sum area if added</font>
00156                                                 totalArea+=area;
00157                                         }
00158                                 }
00159                         }
00160                 }
00161         }
00162 
00163         <font class="comment">// ***************************************************************************</font>
00164 
00165         <font class="comment">// 2. Calc the best area for the dest texture and resize the bitmap</font>
00166         
00167         <font class="comment">// Total area used by the textures + a little more</font>
00168         uint newArea=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (<a class="code" href="namespaceNLMISC.html#a223">raiseToNextPowerOf2</a> (totalArea));
00169         <font class="keywordflow">while</font> ((1&lt;&lt;newArea)&lt;(sint)(mulArea*(float)totalArea))
00170         {
00171                 newArea++;
00172         }
00173 
00174         <font class="comment">// Calc width and height with HEIGHT==WIDTH or HEIGHT=2*WIDTH</font>
00175         uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>=1&lt;&lt;(newArea/2);
00176         uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=1&lt;&lt;(newArea/2 + (newArea&amp;1));
00177 
00178         <font class="comment">// Resize the bitmap and set the pixel format</font>
00179         bitmap.resize (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, CBitmap::RGBA);
00180 
00181         <font class="comment">// Checks</font>
00182         <font class="keywordflow">if</font> (totalArea==0)
00183         {
00184                 <font class="comment">// No texture, ok computed.</font>
00185                 stats.TextureUsed=1;
00186 
00187                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00188         }
00189 
00190         <font class="comment">// ***************************************************************************</font>
00191 
00192         <font class="comment">// 3. Place each texture in the bitmap in uncreasing order</font>
00193         <font class="keyword">typedef</font> std::multimap&lt;sint, CInsertedBitmap&gt; mapInsertedBitmap;
00194         
00195         <font class="comment">// For each texture</font>
00196         MapAreaBitmap::iterator ite=mapArea.end();
00197 
00198         <font class="comment">// Inserted bitmap desc</font>
00199         mapInsertedBitmap inserted;
00200 
00201         <font class="comment">// Max texture height</font>
00202         uint maxTexHeight=0;
00203 
00204         <font class="keywordflow">do</font> 
00205         {
00206                 ite--;
00207                 <a class="code" href="debug_8h.html#a6">nlassert</a> (ite!=mapArea.end());
00208 
00209                 <font class="comment">// Texture</font>
00210                 ITexture *texture=ite-&gt;second.Texture;
00211 
00212                 <font class="comment">// Size of the texture</font>
00213                 uint widthTex=texture-&gt;getWidth();
00214                 uint heightTex=texture-&gt;getHeight();
00215 
00216                 <font class="comment">// Width and height max</font>
00217                 uint widthMax=<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>-widthTex;
00218                 uint heightMax=<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>-heightTex;
00219 
00220                 <font class="comment">// Test against others..</font>
00221                 <font class="keywordtype">bool</font> enter=<font class="keyword">false</font>;
00222 
00223                 <font class="comment">// For each row and each column</font>
00224                 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>&lt;heightMax; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>++)
00225                 {
00226                         <font class="keywordflow">for</font> (uint u=0; u&lt;widthMax; u++)
00227                         {
00228                                 <font class="comment">// Test against others..</font>
00229                                 enter=<font class="keyword">true</font>;
00230 
00231                                 <font class="comment">// Get the first to test</font>
00232                                 mapInsertedBitmap::iterator toTest=inserted.lower_bound ((sint)<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>-(sint)maxTexHeight);
00233                                 <font class="keywordflow">while</font> (toTest!=inserted.end())
00234                                 {
00235                                         <font class="comment">// Make a test ?</font>
00236                                         <font class="keywordflow">if</font> ((sint)(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>+heightTex)&lt;=(toTest-&gt;first))
00237                                         {
00238                                                 <font class="comment">// Ok, end test</font>
00239                                                 <font class="keywordflow">break</font>;
00240                                         }
00241 
00242                                         <font class="comment">// Test it</font>
00243                                         uint otherU=toTest-&gt;second.U;
00244                                         uint otherV=toTest-&gt;second.V;
00245                                         uint otherWidth=toTest-&gt;second.Width;
00246                                         uint otherHeight=toTest-&gt;second.Height;
00247                                         <font class="keywordflow">if</font> ((v&lt;otherV+otherHeight) &amp;&amp; (v+heightTex&gt;otherV) &amp;&amp;
00248                                                 (u&lt;otherU+otherWidth) &amp;&amp; (u+widthTex&gt;otherU))
00249                                         {
00250                                                 <font class="comment">// Collision</font>
00251                                                 enter=<font class="keyword">false</font>;
00252                                                 u=toTest-&gt;second.U+otherWidth-1;
00253                                                 <font class="keywordflow">break</font>;
00254                                         }
00255 
00256                                         <font class="comment">// Next to test</font>
00257                                         toTest++;
00258                                 }
00259 
00260                                 <font class="comment">// Enter ?</font>
00261                                 <font class="keywordflow">if</font> (enter)
00262                                 {
00263                                         <font class="comment">// Ok, enter</font>
00264 
00265                                         <font class="comment">// Insert an inserted descriptor</font>
00266                                         CInsertedBitmap descInserted;
00267                                         descInserted.Width=widthTex;
00268                                         descInserted.Height=heightTex;
00269                                         descInserted.U=u;
00270                                         descInserted.V=<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00271                                         inserted.insert (mapInsertedBitmap::value_type (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, descInserted));
00272         
00273                                         <font class="comment">// Max height</font>
00274                                         <font class="keywordflow">if</font> (heightTex&gt;maxTexHeight)
00275                                                 maxTexHeight=heightTex;
00276 
00277                                         <font class="comment">// Blit in the texture</font>
00278                                         bitmap.blit (texture, u, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
00279 
00280                                         <font class="comment">// Get the descriptor by the name</font>
00281                                         MapBitmapDesc::iterator iteInserted=desc.find (ite-&gt;second.Name);
00282                                         <a class="code" href="debug_8h.html#a6">nlassert</a> (iteInserted!=desc.end());
00283 
00284                                         <font class="comment">// Set the U and V texture coordinates</font>
00285                                         iteInserted-&gt;second.U=(float)(u+1)/(float)<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>;
00286                                         iteInserted-&gt;second.V=(float)(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>+1)/(float)<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>;
00287 
00288                                         <font class="comment">// Set ratio</font>
00289                                         iteInserted-&gt;second.FactorU /= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>;
00290                                         iteInserted-&gt;second.FactorV /= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>;
00291 
00292                                         <font class="comment">// End</font>
00293                                         <font class="keywordflow">break</font>;
00294                                 }
00295 
00296                                 <font class="comment">// next..</font>
00297                         }
00298 
00299                         <font class="comment">// Enter ?</font>
00300                         <font class="keywordflow">if</font> (enter)
00301                                 <font class="keywordflow">break</font>;
00302                 }
00303 
00304                 <font class="comment">// Not enter ?</font>
00305                 <font class="keywordflow">if</font> (!enter)
00306                         <font class="comment">// Texture too small..</font>
00307                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00308         }
00309         <font class="keywordflow">while</font> (ite!=mapArea.begin());
00310 
00311         <font class="comment">// Some stats</font>
00312         stats.TextureUsed=(float)totalArea/(float)(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
00313 
00314         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00315 }
00316 
00317 <font class="comment">// ***************************************************************************</font>
00318 
<a name="l00319"></a><a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#c0">00319</a> <font class="keywordtype">void</font> CCoarseMeshBuild::expand (CBitmap&amp; bitmap)
00320 {
00321         <font class="comment">// Get size</font>
00322         uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>=bitmap.getWidth();
00323         uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=bitmap.getHeight();
00324 
00325         <font class="comment">// Valid size ?</font>
00326         <font class="keywordflow">if</font> ((<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>!=0) &amp;&amp; (<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>!=0))
00327         {
00328                 <font class="comment">// Copy the bitmap</font>
00329                 CBitmap copy=bitmap;
00330 
00331                 <font class="comment">// Resize the bitmap</font>
00332                 bitmap.resize (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>+2);
00333 
00334                 <font class="comment">// Copy old bitmap</font>
00335                 bitmap.blit (&amp;copy, 1, 1);
00336 
00337                 <font class="comment">// Make a top and bottom border</font>
00338                 uint32 *topSrc=(uint32*)&amp;(copy.getPixels()[0]);
00339                 uint32 *topDest=((uint32*)&amp;(bitmap.getPixels()[0]))+1;
00340                 memcpy (topDest, topSrc, 4*<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>);
00341                 uint32 *bottomSrc=topSrc+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>*(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>-1);
00342                 uint32 *bottomDest=((uint32*)&amp;(bitmap.getPixels()[0]))+(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2)*(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>+1)+1;
00343                 memcpy (bottomDest, bottomSrc, 4*<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>);
00344 
00345                 <font class="comment">// Make a left and right border</font>
00346                 uint32 *leftSrc=(uint32*)&amp;(copy.getPixels()[0]);
00347                 uint32 *leftDest=((uint32*)&amp;(bitmap.getPixels()[0]))+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2;
00348                 uint32 *rightSrc=leftSrc+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>-1;
00349                 uint32 *rightDest=leftDest+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+1;
00350                 uint i;
00351                 <font class="keywordflow">for</font> (i=0; i&lt;<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>; i++)
00352                 {
00353                         <font class="comment">// Copy the borders</font>
00354                         *leftDest=*leftSrc;
00355                         *rightDest=*rightSrc;
00356 
00357                         <font class="comment">// Move pointers</font>
00358                         leftDest+=<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2;
00359                         rightDest+=<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2;
00360                         leftSrc+=<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>;
00361                         rightSrc+=<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>;
00362                 }
00363 
00364                 <font class="comment">// Make corners</font>
00365 
00366                 <font class="comment">// Left top</font>
00367                 *(uint32*)&amp;(bitmap.getPixels()[0])=*(uint32*)&amp;(copy.getPixels()[0]);
00368 
00369                 <font class="comment">// Rigth top</font>
00370                 *(((uint32*)&amp;(bitmap.getPixels()[0]))+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+1)=*(((uint32*)&amp;(copy.getPixels()[0]))+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>-1);
00371 
00372                 <font class="comment">// Rigth bottom</font>
00373                 *(((uint32*)&amp;(bitmap.getPixels()[0]))+(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2)*(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>+2)-1)=*(((uint32*)&amp;(copy.getPixels()[0]))+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>-1);
00374 
00375                 <font class="comment">// Left bottom</font>
00376                 *(((uint32*)&amp;(bitmap.getPixels()[0]))+(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>+2)*(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>+1))=*(((uint32*)&amp;(copy.getPixels()[0]))+<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>*(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>-1));
00377         }
00378 }
00379 
00380 <font class="comment">// ***************************************************************************</font>
00381 
<a name="l00382"></a><a class="code" href="classNL3D_1_1CCoarseMeshBuild.html#c2">00382</a> <font class="keywordtype">void</font> CCoarseMeshBuild::remapCoordinates (<font class="keyword">const</font> std::vector&lt;CCoarseMeshDesc&gt;&amp; coarseMeshes, <font class="keyword">const</font> MapBitmapDesc&amp; desc)
00383 {
00384         <font class="comment">// 1. scan each bitmap: calc the area of the bitmap and it its name in the maps sorted by area</font>
00385         <font class="keyword">typedef</font> std::multimap&lt;float, CBitmapDesc&gt; MapAreaBitmap;
00386         MapAreaBitmap mapArea;
00387         uint mesh;
00388         <font class="keywordflow">for</font> (mesh=0; mesh&lt;coarseMeshes.size(); mesh++)
00389         {
00390                 <font class="comment">// Geom mesh pointer</font>
00391                 CMeshGeom *meshGeom=coarseMeshes[mesh].MeshGeom;
00392 
00393                 <font class="comment">// Base mesh pointer</font>
00394                 <font class="keyword">const</font> CMeshBase *meshBase=coarseMeshes[mesh].MeshBase;
00395 
00396                 <font class="comment">// The vertex buffer</font>
00397                 CVertexBuffer &amp;vertexBuffer=const_cast&lt;CVertexBuffer&amp;&gt; (meshGeom-&gt;getVertexBuffer());
00398 
00399                 <font class="comment">// For each matrix block</font>
00400                 uint matrixBlock;
00401                 uint nbMatrixBlock=meshGeom-&gt;getNbMatrixBlock();
00402                 <font class="keywordflow">for</font> (matrixBlock=0; matrixBlock&lt;nbMatrixBlock; matrixBlock++)
00403                 {
00404                         <font class="comment">// For each render pass</font>
00405                         uint renderPass;
00406                         uint numRenderPass=meshGeom-&gt;getNbRdrPass(matrixBlock);
00407                         <font class="keywordflow">for</font> (renderPass=0; renderPass&lt;numRenderPass; renderPass++)
00408                         {
00409                                 <font class="comment">// Render pass material</font>
00410                                 uint32 matId=meshGeom-&gt;getRdrPassMaterial(matrixBlock, renderPass);
00411 
00412                                 <font class="comment">// Checks</font>
00413                                 <a class="code" href="debug_8h.html#a6">nlassert</a> (matId&lt;meshBase-&gt;getNbMaterial());
00414 
00415                                 <font class="comment">// Get the material</font>
00416                                 <font class="keyword">const</font> CMaterial &amp;material=meshBase-&gt;getMaterial(matId);
00417 
00418                                 <font class="comment">// Get the texture</font>
00419                                 ITexture *texture=material.getTexture(0);
00420                                 <font class="keywordflow">if</font> (texture)
00421                                 {
00422                                         <font class="comment">// Get its name</font>
00423                                         std::string name;
00424                                         <font class="keywordflow">if</font> (texture-&gt;supportSharing())
00425                                         {
00426                                                 <font class="comment">// Get sharing name</font>
00427                                                 name=texture-&gt;getShareName();
00428                                         }
00429                                         <font class="keywordflow">else</font>
00430                                         {
00431                                                 <font class="comment">// Build a name</font>
00432                                                 name=toString ((uint)texture);
00433                                         }
00434 
00435                                         <font class="comment">// Find the texture</font>
00436                                         MapBitmapDesc::const_iterator ite=desc.find (name);
00437                                         <a class="code" href="debug_8h.html#a6">nlassert</a> (ite!=desc.end());
00438 
00439                                         <font class="comment">// Descriptor ref</font>
00440                                         <font class="keyword">const</font> CBitmapDesc&amp; descBitmap=ite-&gt;second;
00441 
00442                                         <font class="comment">// Get primitives</font>
00443                                         <font class="keyword">const</font> CPrimitiveBlock &amp;primitiveBlock=meshGeom-&gt;getRdrPassPrimitiveBlock(matrixBlock,renderPass);
00444 
00445                                         <font class="comment">// Set of vertex to remap</font>
00446                                         std::set&lt;uint&gt; vertexToRemap;
00447 
00448                                         <font class="comment">// Remap triangles</font>
00449                                         uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>;
00450                                         <font class="keyword">const</font> uint32 *indexPtr=primitiveBlock.getTriPointer();
00451                                         uint32 numIndex=3*primitiveBlock.getNumTri();
00452                                         <font class="keywordflow">for</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>&lt;numIndex; <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>++)
00453                                                 vertexToRemap.insert (indexPtr[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]);
00454 
00455                                         <font class="comment">// Remap quad</font>
00456                                         indexPtr=primitiveBlock.getQuadPointer();
00457                                         numIndex=4*primitiveBlock.getNumQuad();
00458                                         <font class="keywordflow">for</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>&lt;numIndex; <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>++)
00459                                                 vertexToRemap.insert (indexPtr[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]);
00460 
00461                                         <font class="comment">// Remap the vertex</font>
00462                                         std::set&lt;uint&gt;::iterator iteRemap=vertexToRemap.begin();
00463                                         <font class="keywordflow">while</font> (iteRemap!=vertexToRemap.end())
00464                                         {
00465                                                 <font class="comment">// Remap the vertex</font>
00466                                                 <font class="keywordtype">float</font> *UVCoordinate=(<font class="keywordtype">float</font>*)vertexBuffer.getTexCoordPointer(*iteRemap);
00467                                                 UVCoordinate[0]=UVCoordinate[0]*descBitmap.FactorU+descBitmap.U;
00468                                                 UVCoordinate[1]=UVCoordinate[1]*descBitmap.FactorV+descBitmap.V;
00469 
00470                                                 <font class="comment">// Next vertex</font>
00471                                                 iteRemap++;
00472                                         }                                       
00473                                 }
00474                         }
00475                 }
00476         }
00477 }
00478 
00479 <font class="comment">// ***************************************************************************</font>
00480 
00481 } <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>