Skip to content

Commit

Permalink
fix: fixed extra copy
Browse files Browse the repository at this point in the history
  • Loading branch information
tomezpl committed Dec 31, 2023
1 parent 7d08a98 commit 83b4076
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
41 changes: 23 additions & 18 deletions src/lepus/engine/Objects/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ namespace lepus

}

inline void MoveInternal(Mesh& other)
{
m_Format = other.m_Format;

m_Vertices = other.m_Vertices;
m_szVertices = other.m_szVertices;

m_Indices = other.m_Indices;
m_IndexCount = other.m_IndexCount;

m_IsIndexed = other.m_IsIndexed;
m_OwnData = other.m_OwnData;

other.m_Format = MeshVertexFormat::Invalid;
other.m_IndexCount = 0;
other.m_szVertices = 0;
other.m_Indices = nullptr;
other.m_Vertices = nullptr;
other.m_OwnData = false;
other.m_IsIndexed = false;
}

#define LEPUS_MESH_CONSTRUCTOR(MeshClass) \
public:\
inline MeshClass(lepus::engine::MeshVertexFormat format = lepus::engine::MeshVertexFormat::VVV) {Init(format);} \
Expand Down Expand Up @@ -116,24 +138,7 @@ namespace lepus
// Make sure our data is disposed first if necessary so memory doesn't leak.
Dispose();

m_Format = other.m_Format;

m_Vertices = other.m_Vertices;
m_szVertices = other.m_szVertices;

m_Indices = other.m_Indices;
m_IndexCount = other.m_IndexCount;

m_IsIndexed = other.m_IsIndexed;
m_OwnData = other.m_OwnData;

other.m_Format = MeshVertexFormat::Invalid;
other.m_IndexCount = 0;
other.m_szVertices = 0;
other.m_Indices = nullptr;
other.m_Vertices = nullptr;
other.m_OwnData = false;
other.m_IsIndexed = false;
MoveInternal(other);
}

return *this;
Expand Down
21 changes: 16 additions & 5 deletions src/lepus/gfx/GraphicsEngine/Apis/ApiGL/Types/GLMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,23 @@ namespace lepus
/// @return A reference to a GLMesh object with vertex & index data as well as OpenGL buffers moved from the assigned object.
GLMesh& operator=(GLMesh&& other)
{
*((Mesh*)this) = (Mesh)other;
if (this != &other)
{
Dispose();

MoveInternal(other);

m_IBO = other.m_IBO;
m_VBO = other.m_VBO;
m_HasIBO = other.m_HasIBO;
m_HasVBO = other.m_HasVBO;

other.m_HasIBO = false;
other.m_HasVBO = false;
other.m_IBO = 0;
other.m_VBO = 0;
}

m_IBO = other.m_IBO;
m_VBO = other.m_VBO;
other.m_HasIBO = false;
other.m_HasVBO = false;

return *this;
}
Expand Down

0 comments on commit 83b4076

Please sign in to comment.