]> git.tdb.fi Git - libs/gl.git/blobdiff - source/instancescene.cpp
Change Scene into an abstract base class and add a few subclasses
[libs/gl.git] / source / instancescene.cpp
diff --git a/source/instancescene.cpp b/source/instancescene.cpp
new file mode 100644 (file)
index 0000000..e3e6376
--- /dev/null
@@ -0,0 +1,49 @@
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007-2008, 2010  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "object.h"
+#include "objectinstance.h"
+#include "instancescene.h"
+
+namespace Msp {
+namespace GL {
+
+void InstanceScene::add(const Renderable &r)
+{
+       if(const ObjectInstance *oi = dynamic_cast<const ObjectInstance *>(&r))
+               objects[&oi->get_object()].insert(oi);
+       else
+               renderables.insert(&r);
+}
+
+void InstanceScene::remove(const Renderable &r)
+{
+       if(const ObjectInstance *oi = dynamic_cast<const ObjectInstance *>(&r))
+       {
+               ObjectMap::iterator i = objects.find(&oi->get_object());
+               if(i!=objects.end())
+               {
+                       i->second.erase(oi);
+                       if(i->second.empty())
+                               objects.erase(i);
+               }
+       }
+       else
+               renderables.erase(&r);
+}
+
+void InstanceScene::render(const Tag &tag) const
+{
+       for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               i->first->render(i->second.begin(), i->second.end(), tag);
+
+       for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+               (*i)->render(tag);
+}
+
+} // namespace GL
+} // namespace Msp