]> git.tdb.fi Git - libs/gl.git/blob - source/instancescene.cpp
Add vertex setup state to Renderer
[libs/gl.git] / source / instancescene.cpp
1 #include "object.h"
2 #include "objectinstance.h"
3 #include "instancescene.h"
4 #include "renderer.h"
5
6 namespace Msp {
7 namespace GL {
8
9 void InstanceScene::add(Renderable &r)
10 {
11         renderables[r.get_instance_key()].insert(&r);
12 }
13
14 void InstanceScene::remove(Renderable &r)
15 {
16         InstanceMap::iterator i = renderables.find(r.get_instance_key());
17         if(i!=renderables.end())
18         {
19                 i->second.erase(&r);
20                 if(i->second.empty())
21                         renderables.erase(i);
22         }
23 }
24
25 void InstanceScene::setup_frame(Renderer &renderer)
26 {
27         for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
28                 for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
29                         (*j)->setup_frame(renderer);
30 }
31
32 void InstanceScene::finish_frame()
33 {
34         for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
35                 for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
36                         (*j)->finish_frame();
37 }
38
39 void InstanceScene::render(Renderer &renderer, const Tag &tag) const
40 {
41         if(setup_frustum(renderer))
42         {
43                 for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
44                         for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
45                                 if(!frustum_cull(**j))
46                                         renderer.render(**j, tag);
47         }
48         else
49         {
50                 for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
51                         for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
52                                 renderer.render(**j, tag);
53         }
54 }
55
56 } // namespace GL
57 } // namespace Msp