]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/stage.cpp
Create Stage pipeline when added to a view
[libs/demoscene.git] / source / stage.cpp
index cbe576fa24ba566d2e33bcb2e04201c8c40be027..0ca5c5eec607e1f7143b54edef0eeaf10cb1ea24 100644 (file)
@@ -6,7 +6,8 @@ using namespace std;
 using namespace Msp;
 
 Stage::Stage():
-       pipeline(0)
+       pipeline(0),
+       last_view(0)
 { }
 
 Stage::~Stage()
@@ -14,6 +15,19 @@ Stage::~Stage()
        delete pipeline;
 }
 
+void Stage::add_things(Demo::ThingMap &things, const string &prefix)
+{
+       things[prefix+"camera"] = static_cast<GL::Placeable *>(&camera);
+}
+
+void Stage::set_camera(const GL::Camera &c)
+{
+       camera.set_object_matrix(c.get_object_matrix());
+       camera.set_up_direction(c.get_up_direction());
+       camera.set_field_of_view(c.get_field_of_view());
+       camera.set_depth_clip(c.get_near_clip(), c.get_far_clip());
+}
+
 
 Stage::UseInView::UseInView():
        view(0),
@@ -35,16 +49,53 @@ void Stage::UseInView::validate() const
 
 void Stage::UseInView::start(float, float)
 {
-       view->set_camera(&stage->camera_control.get_camera());
+       if(!stage->pipeline || view!=stage->last_view)
+       {
+               stage->create_pipeline(*view);
+               if(!stage->pipeline)
+                       throw logic_error("null pipeline");
+               stage->last_view = view;
+       }
+
+       view->set_camera(&stage->camera);
        view->set_content(stage->pipeline);
 }
 
 
+Stage::SetCamera::SetCamera():
+       stage(0),
+       camera(0)
+{ }
+
+Stage::SetCamera::SetCamera(Stage &s, const GL::Camera &c):
+       stage(&s),
+       camera(&c)
+{ }
+
+void Stage::SetCamera::validate() const
+{
+       if(!stage)
+               throw logic_error("null stage");
+       if(!camera)
+               throw logic_error("null camera");
+}
+
+void Stage::SetCamera::start(float, float)
+{
+       stage->set_camera(*camera);
+}
+
+
 Stage::UseInView::Loader::Loader(UseInView &u, Demo &d):
        DataFile::DerivedObjectLoader<UseInView, Action::Loader>(u, d)
 {
-       add("view", &Loader::view);
        add("stage", &Loader::stage);
+       add("view", &Loader::view);
+}
+
+void Stage::UseInView::Loader::stage(const string &n)
+{
+       obj.stage = &demo.get_thing<Stage>(n);
 }
 
 void Stage::UseInView::Loader::view(const string &n)
@@ -52,7 +103,20 @@ void Stage::UseInView::Loader::view(const string &n)
        obj.view = &demo.get_thing<GL::View>(n);
 }
 
-void Stage::UseInView::Loader::stage(const string &n)
+
+Stage::SetCamera::Loader::Loader(SetCamera &s, Demo &d):
+       DataFile::DerivedObjectLoader<SetCamera, Action::Loader>(s, d)
+{
+       add("camera", &Loader::camera);
+       add("stage", &Loader::stage);
+}
+
+void Stage::SetCamera::Loader::stage(const string &n)
 {
        obj.stage = &demo.get_thing<Stage>(n);
 }
+
+void Stage::SetCamera::Loader::camera(const string &n)
+{
+       obj.camera = &demo.get_resources().get<GL::Camera>(n);
+}