From 26d70e0eaef1343c823b3da0c9b8753cd4d25ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 16 Aug 2012 17:52:54 +0200 Subject: [PATCH] Added move constructor and move assignment to Mesh. --- src/Mesh.cpp | 25 ++++++++++++++++++++++++- src/Mesh.h | 12 +++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 5bfe0567c..edd0f44bc 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -20,7 +20,16 @@ using namespace std; namespace Magnum { -Mesh::~Mesh() { +Mesh::Mesh(Mesh&& other): + #ifndef MAGNUM_TARGET_GLES + vao(other.vao), + #endif + _primitive(other._primitive), _vertexCount(other._vertexCount), finalized(other.finalized), _buffers(other._buffers), _attributes(other._attributes) +{ + other.vao = 0; +} + +void Mesh::destroy() { for(auto& it: _buffers) delete it.first; @@ -29,6 +38,20 @@ Mesh::~Mesh() { #endif } +Mesh& Mesh::operator=(Mesh&& other) { + destroy(); + + vao = other.vao; + _primitive = other._primitive; + _vertexCount = other._vertexCount; + finalized = other.finalized; + _buffers = other._buffers; + _attributes = other._attributes; + other.vao = 0; + + return *this; +} + Buffer* Mesh::addBuffer(BufferType interleaved) { Buffer* buffer = new Buffer(Buffer::Target::Array); _buffers.insert(make_pair(buffer, make_pair(interleaved, vector()))); diff --git a/src/Mesh.h b/src/Mesh.h index 7985bdd68..10956f569 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -48,9 +48,7 @@ VAOs are used for desktop OpenGL (not in OpenGL ES). */ class MAGNUM_EXPORT Mesh { Mesh(const Mesh& other) = delete; - Mesh(Mesh&& other) = delete; Mesh& operator=(const Mesh& other) = delete; - Mesh& operator=(Mesh&& other) = delete; public: #ifndef MAGNUM_TARGET_GLES @@ -208,12 +206,18 @@ class MAGNUM_EXPORT Mesh { #endif } + /** @brief Move constructor */ + Mesh(Mesh&& other); + /** * @brief Destructor * * Deletes all associated buffers. */ - virtual ~Mesh(); + inline virtual ~Mesh() { destroy(); } + + /** @brief Move assignment */ + Mesh& operator=(Mesh&& other); /** * @brief Whether the mesh is finalized @@ -340,6 +344,8 @@ class MAGNUM_EXPORT Mesh { std::set _attributes; MAGNUM_EXPORT void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type); + + void destroy(); }; }