diff options
author | paradust7 <102263465+paradust7@users.noreply.github.com> | 2022-05-21 15:11:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-22 00:11:49 +0200 |
commit | 2742fef458c3626476193c9e2d1b9231e042e420 (patch) | |
tree | f7682c0a9e2a97578bc44fe344f29fe86bcf233c /src/client | |
parent | bc59fcf5c5cc44ea18e93f64aca9c20be71c1b07 (diff) | |
download | minetest-2742fef458c3626476193c9e2d1b9231e042e420.tar.gz minetest-2742fef458c3626476193c9e2d1b9231e042e420.tar.bz2 minetest-2742fef458c3626476193c9e2d1b9231e042e420.zip |
Fixes needed to use irrArray backed by std::vector (#12263)
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/clientmap.cpp | 39 | ||||
-rw-r--r-- | src/client/clientmap.h | 3 | ||||
-rw-r--r-- | src/client/mapblock_mesh.cpp | 21 | ||||
-rw-r--r-- | src/client/mapblock_mesh.h | 17 |
4 files changed, 47 insertions, 33 deletions
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 46cb115aa..98e3f40d3 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -449,15 +449,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) drawcall_count += draw_order.size(); for (auto &descriptor : draw_order) { - scene::IMeshBuffer *buf; - - if (descriptor.m_use_partial_buffer) { - descriptor.m_partial_buffer->beforeDraw(); - buf = descriptor.m_partial_buffer->getBuffer(); - } - else { - buf = descriptor.m_buffer; - } + scene::IMeshBuffer *buf = descriptor.getBuffer(); // Check and abort if the machine is swapping a lot if (draw.getTimerTime() > 2000) { @@ -501,7 +493,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) m.setTranslation(block_wpos - offset); driver->setTransform(video::ETS_WORLD, m); - driver->drawMeshBuffer(buf); + descriptor.draw(driver); vertex_count += buf->getIndexCount(); } @@ -812,15 +804,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, drawcall_count += draw_order.size(); for (auto &descriptor : draw_order) { - scene::IMeshBuffer *buf; - - if (descriptor.m_use_partial_buffer) { - descriptor.m_partial_buffer->beforeDraw(); - buf = descriptor.m_partial_buffer->getBuffer(); - } - else { - buf = descriptor.m_buffer; - } + scene::IMeshBuffer *buf = descriptor.getBuffer(); // Check and abort if the machine is swapping a lot if (draw.getTimerTime() > 1000) { @@ -845,7 +829,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, m.setTranslation(block_wpos - offset); driver->setTransform(video::ETS_WORLD, m); - driver->drawMeshBuffer(buf); + descriptor.draw(driver); vertex_count += buf->getIndexCount(); } @@ -966,3 +950,18 @@ void ClientMap::updateTransparentMeshBuffers() m_needs_update_transparent_meshes = false; } +scene::IMeshBuffer* ClientMap::DrawDescriptor::getBuffer() +{ + return m_use_partial_buffer ? m_partial_buffer->getBuffer() : m_buffer; +} + +void ClientMap::DrawDescriptor::draw(video::IVideoDriver* driver) +{ + if (m_use_partial_buffer) { + m_partial_buffer->beforeDraw(); + driver->drawMeshBuffer(m_partial_buffer->getBuffer()); + m_partial_buffer->afterDraw(); + } else { + driver->drawMeshBuffer(m_buffer); + } +} diff --git a/src/client/clientmap.h b/src/client/clientmap.h index 6d57f1911..823870c68 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -174,6 +174,9 @@ private: DrawDescriptor(v3s16 pos, const PartialMeshBuffer *buffer) : m_pos(pos), m_partial_buffer(buffer), m_reuse_material(false), m_use_partial_buffer(true) {} + + scene::IMeshBuffer* getBuffer(); + void draw(video::IVideoDriver* driver); }; Client *m_client; diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 868573bf0..965dd5e29 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1162,15 +1162,16 @@ void MapBlockBspTree::traverse(s32 node, v3f viewpoint, std::vector<s32> &output void PartialMeshBuffer::beforeDraw() const { // Patch the indexes in the mesh buffer before draw - - m_buffer->Indices.clear(); - if (!m_vertex_indexes.empty()) { - for (auto index : m_vertex_indexes) - m_buffer->Indices.push_back(index); - } + m_buffer->Indices = std::move(m_vertex_indexes); m_buffer->setDirty(scene::EBT_INDEX); } +void PartialMeshBuffer::afterDraw() const +{ + // Take the data back + m_vertex_indexes = std::move(m_buffer->Indices.steal()); +} + /* MapBlockMesh */ @@ -1514,7 +1515,7 @@ void MapBlockMesh::updateTransparentBuffers(v3f camera_pos, v3s16 block_pos) const auto &t = m_transparent_triangles[i]; if (current_buffer != t.buffer) { if (current_buffer) { - m_transparent_buffers.emplace_back(current_buffer, current_strain); + m_transparent_buffers.emplace_back(current_buffer, std::move(current_strain)); current_strain.clear(); } current_buffer = t.buffer; @@ -1525,7 +1526,7 @@ void MapBlockMesh::updateTransparentBuffers(v3f camera_pos, v3s16 block_pos) } if (!current_strain.empty()) - m_transparent_buffers.emplace_back(current_buffer, current_strain); + m_transparent_buffers.emplace_back(current_buffer, std::move(current_strain)); } void MapBlockMesh::consolidateTransparentBuffers() @@ -1539,7 +1540,7 @@ void MapBlockMesh::consolidateTransparentBuffers() for (const auto &t : m_transparent_triangles) { if (current_buffer != t.buffer) { if (current_buffer != nullptr) { - this->m_transparent_buffers.emplace_back(current_buffer, current_strain); + this->m_transparent_buffers.emplace_back(current_buffer, std::move(current_strain)); current_strain.clear(); } current_buffer = t.buffer; @@ -1550,7 +1551,7 @@ void MapBlockMesh::consolidateTransparentBuffers() } if (!current_strain.empty()) { - this->m_transparent_buffers.emplace_back(current_buffer, current_strain); + this->m_transparent_buffers.emplace_back(current_buffer, std::move(current_strain)); } } diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 72d128038..169b3a8c1 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -140,20 +140,31 @@ private: s32 root = -1; // index of the root node }; +/* + * PartialMeshBuffer + * + * Attach alternate `Indices` to an existing mesh buffer, to make it possible to use different + * indices with the same vertex buffer. + * + * Irrlicht does not currently support this: `CMeshBuffer` ties together a single vertex buffer + * and a single index buffer. There's no way to share these between mesh buffers. + * + */ class PartialMeshBuffer { public: - PartialMeshBuffer(scene::SMeshBuffer *buffer, const std::vector<u16> &vertex_indexes) : - m_buffer(buffer), m_vertex_indexes(vertex_indexes) + PartialMeshBuffer(scene::SMeshBuffer *buffer, std::vector<u16> &&vertex_indexes) : + m_buffer(buffer), m_vertex_indexes(std::move(vertex_indexes)) {} scene::IMeshBuffer *getBuffer() const { return m_buffer; } const std::vector<u16> &getVertexIndexes() const { return m_vertex_indexes; } void beforeDraw() const; + void afterDraw() const; private: scene::SMeshBuffer *m_buffer; - std::vector<u16> m_vertex_indexes; + mutable std::vector<u16> m_vertex_indexes; }; /* |