]> git.tdb.fi Git - libs/gl.git/commitdiff
Collapse the shared part of Mesh::draw and draw_instanced
authorMikko Rasa <tdb@tdb.fi>
Sat, 23 Jan 2021 17:26:28 +0000 (19:26 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 24 Jan 2021 14:14:17 +0000 (16:14 +0200)
source/mesh.cpp
source/mesh.h

index c6543f01cee322bbaa465ea492b2cd15e800bb66..b5535039b44109a2f31ca8cd9c57105001966b64 100644 (file)
@@ -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<Batch>::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<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
-               renderer.draw_instanced(*i, count);
+       if(!count)
+       {
+               for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
+                       renderer.draw(*i);
+       }
+       else
+       {
+               for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
+                       renderer.draw_instanced(*i, count);
+       }
 }
 
 Resource::AsyncLoader *Mesh::load(IO::Seekable &io, const Resources *)
index b4ba0c45151534fab16a0023b05c00cce636d5da..9e086e8770502778167702a3bebaa6cc935f6148 100644 (file)
@@ -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;