From: Mikko Rasa Date: Sat, 23 Jan 2021 17:26:28 +0000 (+0200) Subject: Collapse the shared part of Mesh::draw and draw_instanced X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f5469600171c951438fb62df6427bf968adda28c;p=libs%2Fgl.git Collapse the shared part of Mesh::draw and draw_instanced --- diff --git a/source/mesh.cpp b/source/mesh.cpp index c6543f01..b5535039 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -116,18 +116,7 @@ void Mesh::set_winding(const WindingTest *w) void Mesh::draw(Renderer &renderer) const { - if(manager) - { - manager->resource_used(*this); - if(disallow_rendering) - return; - } - - renderer.set_vertex_setup(&vtx_setup); - renderer.set_winding_test(winding); - - for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) - renderer.draw(*i); + draw(renderer, 0, 0); } void Mesh::draw_instanced(Renderer &renderer, const VertexSetup &vs, unsigned count) const @@ -135,6 +124,11 @@ void Mesh::draw_instanced(Renderer &renderer, const VertexSetup &vs, unsigned co if(vs.get_vertex_array()!=&vertices) throw invalid_argument("Mesh::draw_instanced"); + draw(renderer, &vs, count); +} + +void Mesh::draw(Renderer &renderer, const VertexSetup *vs, unsigned count) const +{ if(manager) { manager->resource_used(*this); @@ -142,11 +136,19 @@ void Mesh::draw_instanced(Renderer &renderer, const VertexSetup &vs, unsigned co return; } - renderer.set_vertex_setup(&vs); + renderer.set_vertex_setup(vs ? vs : &vtx_setup); renderer.set_winding_test(winding); - for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) - renderer.draw_instanced(*i, count); + if(!count) + { + for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) + renderer.draw(*i); + } + else + { + for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) + renderer.draw_instanced(*i, count); + } } Resource::AsyncLoader *Mesh::load(IO::Seekable &io, const Resources *) diff --git a/source/mesh.h b/source/mesh.h index b4ba0c45..9e086e87 100644 --- a/source/mesh.h +++ b/source/mesh.h @@ -88,7 +88,10 @@ public: void draw(Renderer &) const; void draw_instanced(Renderer &, const VertexSetup &, unsigned) const; +private: + void draw(Renderer &, const VertexSetup *, unsigned) const; +public: virtual int get_load_priority() const { return 1; } virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); virtual UInt64 get_data_size() const;