GfxInputDevice.hpp
1 #pragma once
2 #include <Gfx/GfxDevice.hpp>
3 #include <Gfx/GfxExecContext.hpp>
4 #include <ossia/gfx/texture_parameter.hpp>
5 #include <ossia/network/base/device.hpp>
6 #include <ossia/network/base/protocol.hpp>
7 namespace Video
8 {
9 class ExternalInput;
10 }
11 namespace score::gfx {
12 class CameraNode;
13 }
14 namespace Gfx
15 {
16 
17 class simple_texture_input_protocol : public ossia::net::protocol_base
18 {
19 public:
21  : protocol_base{flags{}}
22  {
23  }
24 
25  bool pull(ossia::net::parameter_base&) override { return false; }
26  bool push(const ossia::net::parameter_base&, const ossia::value& v) override
27  {
28  return false;
29  }
30  bool push_raw(const ossia::net::full_parameter_data&) override { return false; }
31  bool observe(ossia::net::parameter_base&, bool) override { return false; }
32  bool update(ossia::net::node_base& node_base) override { return false; }
33 
34  void start_execution() override { }
35  void stop_execution() override { }
36 };
37 
38 class simple_texture_input_parameter : public ossia::gfx::texture_parameter
39 {
40  GfxExecutionAction* context{};
41 
42 public:
43  int32_t node_id{};
44  score::gfx::Node* node{};
45 
47  score::gfx::Node* gfx_n, GfxExecutionAction* ctx, ossia::net::node_base& n)
48  : ossia::gfx::texture_parameter{n}
49  , context{ctx}
50  , node{gfx_n}
51  {
52  node_id = context->ui->register_node(std::unique_ptr<score::gfx::Node>{gfx_n});
53  }
54 
55  void pull_texture(ossia::gfx::port_index idx) override
56  {
57  context->setEdge(port_index{this->node_id, 0}, idx);
58 
60  m.node_id = node_id;
61  context->ui->send_message(std::move(m));
62  }
63 
64  virtual ~simple_texture_input_parameter() { context->ui->unregister_node(node_id); }
65 };
66 
68 class simple_texture_input_node : public ossia::net::node_base
69 {
70  ossia::net::device_base& m_device;
71  node_base* m_parent{};
72  std::unique_ptr<simple_texture_input_parameter> m_parameter;
73 
74 public:
76  score::gfx::Node* gfx_n, GfxExecutionAction* context, ossia::net::device_base& dev,
77  std::string name)
78  : m_device{dev}
79  , m_parameter{
80  std::make_unique<simple_texture_input_parameter>(gfx_n, context, *this)}
81  {
82  m_name = std::move(name);
83  }
84 
85  simple_texture_input_parameter* get_parameter() const override
86  {
87  return m_parameter.get();
88  }
89 
90 private:
91  ossia::net::device_base& get_device() const override { return m_device; }
92  ossia::net::node_base* get_parent() const override { return m_parent; }
93  ossia::net::node_base& set_name(std::string) override { return *this; }
94  ossia::net::parameter_base* create_parameter(ossia::val_type) override
95  {
96  return m_parameter.get();
97  }
98  bool remove_parameter() override { return false; }
99 
100  std::unique_ptr<ossia::net::node_base> make_child(const std::string& name) override
101  {
102  return {};
103  }
104  void removing_child(ossia::net::node_base& node_base) override { }
105 };
106 
107 class simple_texture_input_device : public ossia::net::device_base
108 {
110 
111 public:
113  score::gfx::Node* gfx_n, GfxExecutionAction* context,
114  std::unique_ptr<ossia::net::protocol_base> proto, std::string name)
115  : ossia::net::device_base{std::move(proto)}
116  , root{gfx_n, context, *this, name}
117  {
118  }
119 
120  const simple_texture_input_node& get_root_node() const override { return root; }
121  simple_texture_input_node& get_root_node() override { return root; }
122 };
123 
124 class SCORE_PLUGIN_GFX_EXPORT video_texture_input_protocol
125  : public ossia::net::protocol_base
126 {
127 public:
128  std::shared_ptr<::Video::ExternalInput> camera;
130  std::shared_ptr<::Video::ExternalInput> cam, GfxExecutionAction& ctx);
132 
133  GfxExecutionAction* context{};
134  bool pull(ossia::net::parameter_base&) override;
135  bool push(const ossia::net::parameter_base&, const ossia::value& v) override;
136  bool push_raw(const ossia::net::full_parameter_data&) override;
137  bool observe(ossia::net::parameter_base&, bool) override;
138  bool update(ossia::net::node_base& node_base) override;
139 
140  void start_execution() override;
141  void stop_execution() override;
142 
143  score::gfx::CameraNode* camera_node{};
144 };
145 
146 class SCORE_PLUGIN_GFX_EXPORT video_texture_input_parameter
147  : public ossia::gfx::texture_parameter
148 {
150  GfxExecutionAction* context{};
151 
152 public:
153  std::shared_ptr<::Video::ExternalInput> camera;
154  int32_t node_id{};
155  score::gfx::CameraNode* node{};
156 
158  ossia::net::node_base& n, video_texture_input_protocol& proto);
159  void pull_texture(ossia::gfx::port_index idx) override;
160 
162 };
163 
165 class SCORE_PLUGIN_GFX_EXPORT video_texture_input_node : public ossia::net::node_base
166 {
167  ossia::net::device_base& m_device;
168  node_base* m_parent{};
169  std::unique_ptr<video_texture_input_parameter> m_parameter;
170 
171 public:
172  video_texture_input_node(ossia::net::device_base& dev, std::string name);
174 
175  video_texture_input_parameter* get_parameter() const override;
176 
177 private:
178  ossia::net::device_base& get_device() const override;
179  ossia::net::node_base* get_parent() const override;
180  ossia::net::node_base& set_name(std::string) override;
181  ossia::net::parameter_base* create_parameter(ossia::val_type) override;
182  bool remove_parameter() override;
183 
184  std::unique_ptr<ossia::net::node_base> make_child(const std::string& name) override;
185  void removing_child(ossia::net::node_base& node_base) override;
186 };
187 
188 class SCORE_PLUGIN_GFX_EXPORT video_texture_input_device : public ossia::net::device_base
189 {
191 
192 public:
194  std::unique_ptr<ossia::net::protocol_base> proto, std::string name)
195  : ossia::net::device_base{std::move(proto)}
196  , root{*this, name}
197  {
198  }
200 
201  const video_texture_input_node& get_root_node() const override { return root; }
202  video_texture_input_node& get_root_node() override { return root; }
203 };
204 
205 }
Definition: GfxExecContext.hpp:16
Definition: GfxInputDevice.hpp:108
Definition: GfxInputDevice.hpp:69
Definition: GfxInputDevice.hpp:39
Definition: GfxInputDevice.hpp:18
Definition: GfxInputDevice.hpp:189
Definition: GfxInputDevice.hpp:166
Definition: GfxInputDevice.hpp:148
Definition: GfxInputDevice.hpp:126
Model for rendering a camera feed.
Definition: VideoNode.hpp:122
Root data model for visual nodes.
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:60
Binds the rendering pipeline to ossia processes.
Definition: CameraDevice.cpp:28
Graphics rendering pipeline for ossia score.
Definition: PreviewWidget.hpp:12
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:51