]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/mesh.cpp
Use standard fixed-size integer types
[libs/gl.git] / source / core / mesh.cpp
index 38642d4e26ee7459896429a03775eba3736f1700..371b38b4894a96935cbd2c75326e790e38e45ce6 100644 (file)
@@ -89,7 +89,6 @@ void Mesh::check_buffers(unsigned mask)
                        ibuf = new Buffer;
                        if(!batches.empty())
                                batches.front().change_buffer(ibuf);
-                       vtx_setup.set_index_buffer(*ibuf);
                        dirty |= INDEX_BUFFER;
 
 #ifdef DEBUG
@@ -97,6 +96,9 @@ void Mesh::check_buffers(unsigned mask)
                                vbuf->set_debug_name(debug_name+" [IBO]");
 #endif
                }
+
+               if(!batches.empty())
+                       vtx_setup.set_index_buffer(*ibuf, batches.front().get_index_type());
        }
 }
 
@@ -105,7 +107,7 @@ unsigned Mesh::get_n_vertices() const
        return vertices.size();
 }
 
-float *Mesh::modify_vertex(unsigned i)
+char *Mesh::modify_vertex(unsigned i)
 {
        if(vertices.get_format().empty())
                throw invalid_operation("Mesh::modify_vertex");
@@ -127,7 +129,7 @@ void Mesh::add_batch(const Batch &b)
                bool reallocate = (batches.size()==batches.capacity());
                if(reallocate)
                {
-                       for(vector<Batch>::iterator i=batches.end(); i!=batches.begin(); )
+                       for(auto i=batches.end(); i!=batches.begin(); )
                                (--i)->use_buffer(0);
                }
 
@@ -136,10 +138,10 @@ void Mesh::add_batch(const Batch &b)
                if(reallocate)
                {
                        prev = 0;
-                       for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
+                       for(Batch &a: batches)
                        {
-                               i->use_buffer(ibuf, prev);
-                               prev = &*i;
+                               a.use_buffer(ibuf, prev);
+                               prev = &a;
                        }
                }
                else
@@ -154,8 +156,8 @@ void Mesh::add_batch(const Batch &b)
                        batches.back().set_index_type(existing_type);
                else
                {
-                       for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
-                               i->set_index_type(added_type);
+                       for(Batch &a: batches)
+                               a.set_index_type(added_type);
                }
        }
 
@@ -200,13 +202,13 @@ void Mesh::draw(Renderer &renderer, const VertexSetup *vs, unsigned count) const
 
        if(!count)
        {
-               for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
-                       renderer.draw(*i);
+               for(const Batch &b: batches)
+                       renderer.draw(b);
        }
        else
        {
-               for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
-                       renderer.draw_instanced(*i, count);
+               for(const Batch &b: batches)
+                       renderer.draw_instanced(b, count);
        }
 }
 
@@ -224,9 +226,9 @@ Resource::AsyncLoader *Mesh::load(IO::Seekable &io, const Resources *)
        return new AsyncLoader(*this, io);
 }
 
-UInt64 Mesh::get_data_size() const
+uint64_t Mesh::get_data_size() const
 {
-       UInt64 size = 0;
+       uint64_t size = 0;
        if(vbuf)
                size += vbuf->get_size();
        if(ibuf)
@@ -272,14 +274,14 @@ Mesh::Loader::Loader(Mesh &m, bool g):
        add("winding",  &Mesh::face_winding);
 }
 
-void Mesh::Loader::storage(const vector<VertexAttribute> &a)
+void Mesh::Loader::storage(const vector<VertexAttribute> &attrs)
 {
-       if(a.empty())
+       if(attrs.empty())
                throw invalid_argument("No vertex attributes");
 
        VertexFormat fmt;
-       for(vector<VertexAttribute>::const_iterator i=a.begin(); i!=a.end(); ++i)
-               fmt = (fmt, *i);
+       for(VertexAttribute a: attrs)
+               fmt = (fmt, a);
        obj.storage(fmt);
 }