]> git.tdb.fi Git - libs/gl.git/blob - source/render/scene.cpp
Rework multisample resolve to use resolve attachments
[libs/gl.git] / source / render / scene.cpp
1 #include <msp/datafile/collection.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
4 #include "camera.h"
5 #include "instancearray.h"
6 #include "objectinstance.h"
7 #include "occludedscene.h"
8 #include "orderedscene.h"
9 #include "renderer.h"
10 #include "scene.h"
11 #include "simplescene.h"
12 #include "zsortedscene.h"
13
14 using namespace std;
15
16 namespace Msp {
17 namespace GL {
18
19 Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry()
20 {
21         static Scene::GenericLoader::TypeRegistry registry;
22         static bool initialized = false;
23         if(!initialized)
24         {
25                 initialized = true;
26                 register_type<SimpleScene>("simple");
27                 register_type<ZSortedScene>("zsorted");
28                 register_type<OrderedScene>("ordered");
29                 register_type<OccludedScene>("occluded");
30         }
31         return registry;
32 }
33
34
35 unsigned Scene::Loader::inline_counter = 0;
36
37 Scene::Loader::Loader(Scene &s, Collection &c, ContentMap *m):
38         DataFile::CollectionObjectLoader<Scene>(s, &c),
39         content(m)
40 {
41         add("array", &Loader::array);
42         add("object", &Loader::object);
43         add("object", &Loader::object_tagged);
44         add("scene", &Loader::scene);
45         add("scene", &Loader::scene_inline);
46 }
47
48 void Scene::Loader::array(const string &n)
49 {
50         RefPtr<InstanceArray<> > arr = new InstanceArray<>(get_collection().get<GL::Object>(n));
51         load_sub(*arr);
52         get_collection().add(format("_scene_array_%d.array", ++inline_counter), arr.get());
53         obj.add(*arr.release());
54 }
55
56 void Scene::Loader::object(const string &n)
57 {
58         object_tagged(n, string());
59 }
60
61 void Scene::Loader::object_tagged(const string &n, const string &t)
62 {
63         RefPtr<ObjectInstance> inst = new ObjectInstance(get_collection().get<GL::Object>(n));
64         load_sub(*inst);
65         get_collection().add(format("_scene_object_%d.inst", ++inline_counter), inst.get());
66         if(content && !t.empty())
67                 (*content)[t] = inst.get();
68         obj.add(*inst.release());
69 }
70
71 void Scene::Loader::scene(const string &n)
72 {
73         obj.add(get_collection().get<Scene>(n));
74 }
75
76 void Scene::Loader::scene_inline()
77 {
78         GenericLoader ldr(get_collection());
79         load_sub_with(ldr);
80         Scene *scene = ldr.store_object(get_collection(), format("_scene_%d.scene", ++inline_counter));
81         obj.add(*scene);
82 }
83
84 } // namespace GL
85 } // namespace Msp