From 83b407689893694e8cabb37baf722195cfbac837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zaj=C4=85c?= Date: Sun, 31 Dec 2023 02:19:12 +0000 Subject: [PATCH] fix: fixed extra copy --- src/lepus/engine/Objects/Mesh.h | 41 +++++++++++-------- .../GraphicsEngine/Apis/ApiGL/Types/GLMesh.h | 21 +++++++--- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/lepus/engine/Objects/Mesh.h b/src/lepus/engine/Objects/Mesh.h index 3163c19..1595afd 100644 --- a/src/lepus/engine/Objects/Mesh.h +++ b/src/lepus/engine/Objects/Mesh.h @@ -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);} \ @@ -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; diff --git a/src/lepus/gfx/GraphicsEngine/Apis/ApiGL/Types/GLMesh.h b/src/lepus/gfx/GraphicsEngine/Apis/ApiGL/Types/GLMesh.h index e729e27..b82954e 100644 --- a/src/lepus/gfx/GraphicsEngine/Apis/ApiGL/Types/GLMesh.h +++ b/src/lepus/gfx/GraphicsEngine/Apis/ApiGL/Types/GLMesh.h @@ -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; }