Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
compositor.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef PIPELINE_H
20 #define PIPELINE_H
21 
22 #include <vector>
23 #include <memory>
24 #include <list>
25 
26 #include "generic/managed.h"
27 #include "generic/property.h"
28 
29 #include "renderers/renderer.h"
30 #include "types.h"
31 #include "viewport.h"
32 #include "partitioner.h"
33 #include "pipeline.h"
34 
35 namespace smlt {
36 
37 class Compositor:
38  public RefCounted<Compositor> {
39 
40 public:
41  Compositor(Window* window);
42  virtual ~Compositor();
43 
44  PipelinePtr new_pipeline(const std::string& name,
45  StagePtr stage,
46  CameraPtr camera,
47  const Viewport& viewport=Viewport(),
48  TextureID target=TextureID(),
49  int32_t priority=0
50  );
51 
52  PipelinePtr render(StagePtr stage, CameraPtr camera);
53 
54  std::list<PipelinePtr>::iterator begin() {
55  return ordered_pipelines_.begin();
56  }
57 
58  std::list<PipelinePtr>::iterator end() {
59  return ordered_pipelines_.end();
60  }
61 
62  PipelinePtr find_pipeline(const std::string& name);
63  bool destroy_pipeline(const std::string& name);
64  void destroy_all_pipelines();
65  void destroy_pipeline_immediately(const std::string& name);
66 
67  bool has_pipeline(const std::string& name);
68 
69  //void set_batcher(Batcher::ptr batcher);
70  void set_renderer(Renderer *renderer);
71 
72  void run();
73  void clean_destroyed_pipelines();
74 
75  sig::signal<void (Pipeline&)>& signal_pipeline_started() { return signal_pipeline_started_; }
76  sig::signal<void (Pipeline&)>& signal_pipeline_finished() { return signal_pipeline_finished_; }
77 
78  void destroy_object(PipelinePtr pipeline) {
79  destroy_pipeline(pipeline->name());
80  }
81 
82  void destroy_object_immediately(PipelinePtr pipeline) {
83  // FIXME: This doesn't destroy immediately
84  destroy_pipeline(pipeline->name());
85  }
86 
87 private:
88  void sort_pipelines();
89  void run_pipeline(PipelinePtr stage, int& actors_rendered);
90 
91  Window* window_ = nullptr;
92  Renderer* renderer_ = nullptr;
93  batcher::RenderQueue render_queue_;
94 
95  std::list<std::shared_ptr<Pipeline>> pool_;
96  std::list<PipelinePtr> ordered_pipelines_;
97  std::set<PipelinePtr> queued_for_destruction_;
98 
99  sig::signal<void (Pipeline&)> signal_pipeline_started_;
100  sig::signal<void (Pipeline&)> signal_pipeline_finished_;
101 
102  friend class Pipeline;
103 
104  std::set<RenderTarget*> targets_rendered_this_frame_;
105 
106  sig::connection clean_up_connection_;
107 public:
108  S_DEFINE_PROPERTY(window, &Compositor::window_);
109 };
110 
111 }
112 
113 #endif // PIPELINE_H
smlt::sig::Connection
Definition: signal.h:65
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::Window
Definition: window.h:65
smlt::Compositor
Definition: compositor.h:38
smlt::batcher::RenderQueue
Definition: render_queue.h:156
smlt::UniqueID< TexturePtr >
smlt::Pipeline
Definition: pipeline.h:21
smlt::Renderer
Definition: renderer.h:40
smlt::default_init_ptr< Pipeline >
smlt::Viewport
Definition: viewport.h:44
smlt::sig::signal
Definition: signal.h:319