Browse Source

Added move constructor and move assignment to Mesh.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
26d70e0eae
  1. 25
      src/Mesh.cpp
  2. 12
      src/Mesh.h

25
src/Mesh.cpp

@ -20,7 +20,16 @@ using namespace std;
namespace Magnum { 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) for(auto& it: _buffers)
delete it.first; delete it.first;
@ -29,6 +38,20 @@ Mesh::~Mesh() {
#endif #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* Mesh::addBuffer(BufferType interleaved) {
Buffer* buffer = new Buffer(Buffer::Target::Array); Buffer* buffer = new Buffer(Buffer::Target::Array);
_buffers.insert(make_pair(buffer, make_pair(interleaved, vector<Attribute>()))); _buffers.insert(make_pair(buffer, make_pair(interleaved, vector<Attribute>())));

12
src/Mesh.h

@ -48,9 +48,7 @@ VAOs are used for desktop OpenGL (not in OpenGL ES).
*/ */
class MAGNUM_EXPORT Mesh { class MAGNUM_EXPORT Mesh {
Mesh(const Mesh& other) = delete; Mesh(const Mesh& other) = delete;
Mesh(Mesh&& other) = delete;
Mesh& operator=(const Mesh& other) = delete; Mesh& operator=(const Mesh& other) = delete;
Mesh& operator=(Mesh&& other) = delete;
public: public:
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -208,12 +206,18 @@ class MAGNUM_EXPORT Mesh {
#endif #endif
} }
/** @brief Move constructor */
Mesh(Mesh&& other);
/** /**
* @brief Destructor * @brief Destructor
* *
* Deletes all associated buffers. * Deletes all associated buffers.
*/ */
virtual ~Mesh(); inline virtual ~Mesh() { destroy(); }
/** @brief Move assignment */
Mesh& operator=(Mesh&& other);
/** /**
* @brief Whether the mesh is finalized * @brief Whether the mesh is finalized
@ -340,6 +344,8 @@ class MAGNUM_EXPORT Mesh {
std::set<GLuint> _attributes; std::set<GLuint> _attributes;
MAGNUM_EXPORT void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type); MAGNUM_EXPORT void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type);
void destroy();
}; };
} }

Loading…
Cancel
Save