X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fmesh.cpp;h=e2dd853c448dff6c25259bcb42aa46d6a1433c70;hb=f853ca0a365ae8b43ba8b2f4d6f21cd1c2bd4bd5;hp=de05102a358a5665a51b12cd0c345c21441052d5;hpb=d493917dbc215cd6ba3f8773a52a289d9f14380d;p=libs%2Fgl.git diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index de05102a..e2dd853c 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -1,42 +1,19 @@ -#include -#include -#include -#include #include "buffer.h" #include "error.h" #include "mesh.h" #include "renderer.h" #include "resourcemanager.h" -#include "vertexsetup.h" using namespace std; namespace Msp { namespace GL { -Mesh::Mesh(ResourceManager *rm) +Mesh::Mesh(const VertexFormat &f) { - init(rm); -} - -Mesh::Mesh(const VertexFormat &f, ResourceManager *rm) -{ - init(rm); storage(f); } -void Mesh::init(ResourceManager *rm) -{ - vbuf = 0; - ibuf = 0; - dirty = 0; - disallow_rendering = false; - face_winding = NON_MANIFOLD; - - if(rm) - set_manager(rm); -} - Mesh::~Mesh() { set_manager(0); @@ -102,12 +79,12 @@ void Mesh::check_buffers(unsigned mask) } } -unsigned Mesh::get_n_vertices() const +size_t Mesh::get_n_vertices() const { return vertices.size(); } -char *Mesh::modify_vertex(unsigned i) +char *Mesh::modify_vertex(size_t i) { if(vertices.get_format().empty()) throw invalid_operation("Mesh::modify_vertex"); @@ -129,7 +106,7 @@ void Mesh::add_batch(const Batch &b) bool reallocate = (batches.size()==batches.capacity()); if(reallocate) { - for(vector::iterator i=batches.end(); i!=batches.begin(); ) + for(auto i=batches.end(); i!=batches.begin(); ) (--i)->use_buffer(0); } @@ -138,10 +115,10 @@ void Mesh::add_batch(const Batch &b) if(reallocate) { prev = 0; - for(vector::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 @@ -156,8 +133,8 @@ void Mesh::add_batch(const Batch &b) batches.back().set_index_type(existing_type); else { - for(vector::iterator i=batches.begin(); i!=batches.end(); ++i) - i->set_index_type(added_type); + for(Batch &a: batches) + a.set_index_type(added_type); } } @@ -202,13 +179,13 @@ void Mesh::draw(Renderer &renderer, const VertexSetup *vs, unsigned count) const if(!count) { - for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) - renderer.draw(*i); + for(const Batch &b: batches) + renderer.draw(b); } else { - for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) - renderer.draw_instanced(*i, count); + for(const Batch &b: batches) + renderer.draw_instanced(b, count); } } @@ -226,9 +203,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) @@ -274,14 +251,14 @@ Mesh::Loader::Loader(Mesh &m, bool g): add("winding", &Mesh::face_winding); } -void Mesh::Loader::storage(const vector &a) +void Mesh::Loader::storage(const vector &attrs) { - if(a.empty()) + if(attrs.empty()) throw invalid_argument("No vertex attributes"); VertexFormat fmt; - for(vector::const_iterator i=a.begin(); i!=a.end(); ++i) - fmt = (fmt, *i); + for(VertexAttribute a: attrs) + fmt = (fmt, a); obj.storage(fmt); }