X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finstancescene.cpp;fp=source%2Finstancescene.cpp;h=e3e63767243a1a88ba1ea98655bb480b6ad4584b;hb=9addd3d476245415244e59333a36a8fc0eae42bf;hp=0000000000000000000000000000000000000000;hpb=6fa59eb26c39443eb44feecd17b7a8ea45411730;p=libs%2Fgl.git diff --git a/source/instancescene.cpp b/source/instancescene.cpp new file mode 100644 index 00000000..e3e63767 --- /dev/null +++ b/source/instancescene.cpp @@ -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(&r)) + objects[&oi->get_object()].insert(oi); + else + renderables.insert(&r); +} + +void InstanceScene::remove(const Renderable &r) +{ + if(const ObjectInstance *oi = dynamic_cast(&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