mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Move data directly rather than copying
This commit is contained in:
parent
818ac9ea3d
commit
b734119d05
@ -199,6 +199,9 @@ class ISkinnedMesh : public IAnimatedMesh
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
virtual SSkinMeshBuffer *addMeshBuffer() = 0;
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
virtual void addMeshBuffer(SSkinMeshBuffer &&meshbuf) = 0;
|
||||
|
||||
//! Adds a new joint to the mesh, access it as last one
|
||||
virtual SJoint *addJoint(SJoint *parent = 0) = 0;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "IMeshBuffer.h"
|
||||
#include "S3DVertex.h"
|
||||
#include "irrArray.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@ -24,10 +25,14 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
||||
MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
|
||||
HWBuffer(NULL),
|
||||
BoundingBoxNeedsRecalculated(true)
|
||||
{}
|
||||
|
||||
//! Constructor for standard vertices
|
||||
SSkinMeshBuffer(core::array<video::S3DVertex> &&vertices, core::array<u16> &&indices) :
|
||||
SSkinMeshBuffer()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("SSkinMeshBuffer");
|
||||
#endif
|
||||
Vertices_Standard = vertices;
|
||||
Indices = indices;
|
||||
}
|
||||
|
||||
//! Get Material of this buffer.
|
||||
@ -303,26 +308,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
||||
}
|
||||
|
||||
//! append the vertices and indices to the current buffer
|
||||
void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {
|
||||
if (vertices == getVertices())
|
||||
throw std::logic_error("can't append own vertices");
|
||||
|
||||
if (VertexType != video::EVT_STANDARD)
|
||||
throw std::logic_error("invalid vertex type");
|
||||
|
||||
const u32 prevVertexCount = getVertexCount();
|
||||
|
||||
Vertices_Standard.reallocate(prevVertexCount + numVertices);
|
||||
for (u32 i=0; i < numVertices; ++i) {
|
||||
Vertices_Standard.push_back(static_cast<const video::S3DVertex* const>(vertices)[i]);
|
||||
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex* const>(vertices)[i].Pos);
|
||||
}
|
||||
|
||||
Indices.reallocate(getIndexCount() + numIndices);
|
||||
for (u32 i=0; i < numIndices; ++i) {
|
||||
Indices.push_back(indices[i] + prevVertexCount);
|
||||
}
|
||||
}
|
||||
void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {}
|
||||
|
||||
//! get the current hardware mapping hint for vertex buffers
|
||||
E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
|
||||
|
@ -45,6 +45,9 @@ class array
|
||||
{
|
||||
}
|
||||
|
||||
//! Move constructor
|
||||
array(std::vector<T> &&data) : m_data(data), is_sorted(false) {}
|
||||
|
||||
//! Reallocates the array, make it bigger or smaller.
|
||||
/** \param new_size New size of array.
|
||||
\param canShrink Specifies whether the array is reallocated even if
|
||||
|
@ -429,9 +429,8 @@ void CGLTFMeshFileLoader::MeshExtractor::loadMesh(
|
||||
indices = generateIndices(vertices->size());
|
||||
}
|
||||
|
||||
auto *meshbuf = m_irr_model->addMeshBuffer();
|
||||
meshbuf->append(vertices->data(), vertices->size(),
|
||||
indices.data(), indices.size());
|
||||
m_irr_model->addMeshBuffer(
|
||||
SSkinMeshBuffer(std::move(*vertices), std::move(indices)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <optional>
|
||||
#include "CBoneSceneNode.h"
|
||||
#include "IAnimatedMeshSceneNode.h"
|
||||
#include "SSkinMeshBuffer.h"
|
||||
#include "os.h"
|
||||
|
||||
namespace
|
||||
@ -1061,6 +1062,11 @@ scene::SSkinMeshBuffer *CSkinnedMesh::addMeshBuffer()
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void CSkinnedMesh::addMeshBuffer(SSkinMeshBuffer &&meshbuf)
|
||||
{
|
||||
LocalBuffers.push_back(new SSkinMeshBuffer(std::move(meshbuf)));
|
||||
}
|
||||
|
||||
CSkinnedMesh::SJoint *CSkinnedMesh::addJoint(SJoint *parent)
|
||||
{
|
||||
SJoint *joint = new SJoint;
|
||||
|
@ -129,6 +129,9 @@ class CSkinnedMesh : public ISkinnedMesh
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
SSkinMeshBuffer *addMeshBuffer() override;
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
void addMeshBuffer(SSkinMeshBuffer &&meshbuf) override;
|
||||
|
||||
//! Adds a new joint to the mesh, access it as last one
|
||||
SJoint *addJoint(SJoint *parent = 0) override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user