@@ -31,6 +31,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
31
31
#include < algorithm>
32
32
#include " client/renderingengine.h"
33
33
34
+ // struct MeshBufListList
35
+ void MeshBufListList::clear ()
36
+ {
37
+ for (auto &list : lists)
38
+ list.clear ();
39
+ }
40
+
41
+ void MeshBufListList::add (scene::IMeshBuffer *buf, v3s16 position, u8 layer)
42
+ {
43
+ // Append to the correct layer
44
+ std::vector<MeshBufList> &list = lists[layer];
45
+ const video::SMaterial &m = buf->getMaterial ();
46
+ for (MeshBufList &l : list) {
47
+ // comparing a full material is quite expensive so we don't do it if
48
+ // not even first texture is equal
49
+ if (l.m .TextureLayer [0 ].Texture != m.TextureLayer [0 ].Texture )
50
+ continue ;
51
+
52
+ if (l.m == m) {
53
+ l.bufs .emplace_back (position, buf);
54
+ return ;
55
+ }
56
+ }
57
+ MeshBufList l;
58
+ l.m = m;
59
+ l.bufs .emplace_back (position, buf);
60
+ list.emplace_back (l);
61
+ }
62
+
63
+ // ClientMap
64
+
34
65
ClientMap::ClientMap (
35
66
Client *client,
36
67
MapDrawControl &control,
@@ -182,9 +213,7 @@ void ClientMap::updateDrawList()
182
213
if not seen on display
183
214
*/
184
215
185
- if (block->mesh ) {
186
- block->mesh ->updateCameraOffset (m_camera_offset);
187
- } else {
216
+ if (!block->mesh ) {
188
217
// Ignore if mesh doesn't exist
189
218
continue ;
190
219
}
@@ -229,50 +258,6 @@ void ClientMap::updateDrawList()
229
258
g_profiler->avg (" MapBlocks loaded [#]" , blocks_loaded);
230
259
}
231
260
232
- struct MeshBufList
233
- {
234
- video::SMaterial m;
235
- std::vector<scene::IMeshBuffer*> bufs;
236
- };
237
-
238
- struct MeshBufListList
239
- {
240
- /* !
241
- * Stores the mesh buffers of the world.
242
- * The array index is the material's layer.
243
- * The vector part groups vertices by material.
244
- */
245
- std::vector<MeshBufList> lists[MAX_TILE_LAYERS];
246
-
247
- void clear ()
248
- {
249
- for (auto &list : lists)
250
- list.clear ();
251
- }
252
-
253
- void add (scene::IMeshBuffer *buf, u8 layer)
254
- {
255
- // Append to the correct layer
256
- std::vector<MeshBufList> &list = lists[layer];
257
- const video::SMaterial &m = buf->getMaterial ();
258
- for (MeshBufList &l : list) {
259
- // comparing a full material is quite expensive so we don't do it if
260
- // not even first texture is equal
261
- if (l.m .TextureLayer [0 ].Texture != m.TextureLayer [0 ].Texture )
262
- continue ;
263
-
264
- if (l.m == m) {
265
- l.bufs .push_back (buf);
266
- return ;
267
- }
268
- }
269
- MeshBufList l;
270
- l.m = m;
271
- l.bufs .push_back (buf);
272
- list.push_back (l);
273
- }
274
- };
275
-
276
261
void ClientMap::renderMap (video::IVideoDriver* driver, s32 pass)
277
262
{
278
263
bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
@@ -317,6 +302,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
317
302
MeshBufListList drawbufs;
318
303
319
304
for (auto &i : m_drawlist) {
305
+ v3s16 block_pos = i.first ;
320
306
MapBlock *block = i.second ;
321
307
322
308
// If the mesh of the block happened to get deleted, ignore it
@@ -382,7 +368,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
382
368
material.setFlag (video::EMF_WIREFRAME,
383
369
m_control.show_wireframe );
384
370
385
- drawbufs.add (buf, layer);
371
+ drawbufs.add (buf, block_pos, layer);
386
372
}
387
373
}
388
374
}
@@ -391,6 +377,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
391
377
392
378
TimeTaker draw (" Drawing mesh buffers" );
393
379
380
+ core::matrix4 m; // Model matrix
381
+ v3f offset = intToFloat (m_camera_offset, BS);
382
+
394
383
// Render all layers in order
395
384
for (auto &lists : drawbufs.lists ) {
396
385
for (MeshBufList &list : lists) {
@@ -402,7 +391,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
402
391
}
403
392
driver->setMaterial (list.m );
404
393
405
- for (scene::IMeshBuffer *buf : list.bufs ) {
394
+ for (auto &pair : list.bufs ) {
395
+ scene::IMeshBuffer *buf = pair.second ;
396
+
397
+ v3f block_wpos = intToFloat (pair.first * MAP_BLOCKSIZE, BS);
398
+ m.setTranslation (block_wpos - offset);
399
+
400
+ driver->setTransform (video::ETS_WORLD, m);
406
401
driver->drawMeshBuffer (buf);
407
402
vertex_count += buf->getVertexCount ();
408
403
}
@@ -607,5 +602,3 @@ void ClientMap::PrintInfo(std::ostream &out)
607
602
{
608
603
out<<" ClientMap: " ;
609
604
}
610
-
611
-
0 commit comments