Loading...
Searching...
No Matches
GfxExecNode.hpp
1#pragma once
2
3#include <State/ValueConversion.hpp>
4
5#include <Process/ExecutionContext.hpp>
6
7#include <Gfx/GfxContext.hpp>
8#include <Gfx/GfxDevice.hpp>
9#include <Gfx/GfxExecContext.hpp>
10
11#include <ossia/dataflow/graph_edge.hpp>
12#include <ossia/dataflow/graph_node.hpp>
13#include <ossia/dataflow/port.hpp>
14#include <ossia/detail/lockfree_queue.hpp>
15#include <ossia/detail/triple_buffer.hpp>
16
17#include <atomic>
18#include <memory>
19#include <vector>
20
21#include <score_plugin_gfx_export.h>
22
23namespace Gfx
24{
25
26template <typename Vector>
27int64_t
28index_of(Vector&& v, const typename std::remove_reference_t<Vector>::value_type& t)
29{
30 if(auto it = ossia::find(v, t); it != v.end())
31 {
32 return std::distance(v.begin(), it);
33 }
34 return -1;
35}
36
38{
39 ossia::value value{};
40 ossia::value_port* port{};
41 bool changed{};
42};
43
44using exec_controls = std::vector<std::shared_ptr<exec_control>>;
45class SCORE_PLUGIN_GFX_EXPORT gfx_exec_node : public ossia::graph_node
46{
47public:
49
50 exec_controls controls;
51 exec_controls control_outs;
52
55 {
56 ossia::triple_buffer<ossia::value> latest;
59 ossia::value scratch;
60 };
63 std::vector<std::unique_ptr<ui_control_out>> ui_control_outs;
64 std::atomic_bool notify_ui{};
65
66 GfxExecutionAction* exec_context{};
67 gfx_exec_node(GfxExecutionAction& e_ctx)
68 : exec_context{&e_ctx}
69 {
70 }
71
72 const std::shared_ptr<control>& add_control()
73 {
74 auto port = new ossia::value_inlet;
75 m_inlets.push_back(port);
76
77 controls.push_back(std::make_shared<control>());
78 auto& c = controls.back();
79 c->port = &**port;
80 c->changed = true;
81
82 return c;
83 }
84
85 const std::shared_ptr<control>& add_control_out()
86 {
87 auto port = new ossia::value_outlet;
88 m_outlets.push_back(port);
89
90 ui_control_outs.push_back(std::make_unique<ui_control_out>());
91 control_outs.push_back(std::make_shared<control>());
92 auto& c = control_outs.back();
93 c->port = &**port;
94 c->changed = false;
95
96 return c;
97 }
98
99 auto add_value_port()
100 {
101 auto port = new ossia::value_inlet;
102 m_inlets.push_back(port);
103 return port;
104 }
105
106 auto add_texture()
107 {
108 auto port = new ossia::texture_inlet;
109 m_inlets.push_back(port);
110 return port;
111 }
112
113 auto add_texture_out()
114 {
115 auto port = new ossia::texture_outlet;
116 m_outlets.push_back(port);
117 return port;
118 }
119
120 auto add_geometry()
121 {
122 auto port = new ossia::geometry_inlet;
123 m_inlets.push_back(port);
124 return port;
125 }
126
127 auto add_geometry_out()
128 {
129 auto port = new ossia::geometry_outlet;
130 m_outlets.push_back(port);
131 return port;
132 }
133
134 auto add_audio()
135 {
136 auto port = new ossia::audio_inlet;
137 m_inlets.push_back(port);
138 return port;
139 }
140
141 ~gfx_exec_node();
142
143 int32_t id{score::gfx::invalid_node_index};
144 std::atomic_int32_t script_index{0};
145 ossia::time_value m_last_flicks{};
146 void run(const ossia::token_request& tk, ossia::exec_state_facade) noexcept override;
147
148 void link_cable_to_inlet(ossia::inlet* inlet, int inlet_i);
149 using ossia::graph_node::m_inlets;
150 using ossia::graph_node::m_outlets;
151};
152
153struct SCORE_PLUGIN_GFX_EXPORT con_unvalidated
154{
155 const Execution::Context& ctx;
156 const std::size_t i;
157 const int32_t script_index{};
158 std::weak_ptr<gfx_exec_node> weak_node;
159 void operator()(const ossia::value& val);
160};
161
162}
Definition GfxExecContext.hpp:19
Definition GfxExecNode.hpp:46
std::vector< std::unique_ptr< ui_control_out > > ui_control_outs
Definition GfxExecNode.hpp:63
Binds the rendering pipeline to ossia processes.
Definition AssetTable.cpp:7
Definition ExecutionContext.hpp:208
Definition GfxExecNode.hpp:154
Definition GfxExecNode.hpp:38
The latest value of a control output, on its way to the views.
Definition GfxExecNode.hpp:55
ossia::value scratch
Definition GfxExecNode.hpp:59