]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/mesh.cpp
Add correct copy and move semantics to most classes
[libs/gl.git] / source / core / mesh.cpp
index b5628eb10c860bbc758b17e08b7db045bea7b65c..208126ef26c477ed5adf8ca61f357400ca44ee73 100644 (file)
@@ -14,6 +14,22 @@ Mesh::Mesh(const VertexFormat &f)
        storage(f);
 }
 
+Mesh::Mesh(Mesh &&other):
+       Resource(move(other)),
+       vertices(move(other.vertices)),
+       batches(move(other.batches)),
+       vbuf(other.vbuf),
+       ibuf(other.ibuf),
+       vtx_setup(move(other.vtx_setup)),
+       dirty(other.dirty),
+       disallow_rendering(other.disallow_rendering),
+       face_winding(other.face_winding),
+       debug_name(move(other.debug_name))
+{
+       other.vbuf = 0;
+       other.ibuf = 0;
+}
+
 Mesh::~Mesh()
 {
        set_manager(0);
@@ -94,11 +110,11 @@ char *Mesh::modify_vertex(size_t i)
        return vertices.modify(i);
 }
 
-void Mesh::add_batch(const Batch &b)
+void Mesh::add_batch(Batch &&b)
 {
        if(batches.empty())
        {
-               batches.push_back(b);
+               batches.emplace_back(move(b));
                if(ibuf)
                        batches.back().use_buffer(ibuf);
        }
@@ -114,7 +130,7 @@ void Mesh::add_batch(const Batch &b)
                }
 
                Batch *prev = &batches.back();
-               batches.push_back(b);
+               batches.emplace_back(move(b));
                if(reallocate)
                {
                        prev = 0;
@@ -281,7 +297,7 @@ void Mesh::Loader::batch(PrimitiveType p)
 {
        Batch btc(p);
        load_sub(btc);
-       obj.add_batch(btc);
+       obj.add_batch(move(btc));
 }