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