1 #ifndef OGLPLUS_TEXGEN_RENDER_GRAPH_HPP
9 #define OGLPLUS_TEXGEN_RENDER_GRAPH_HPP
17 namespace eagine::oglp::texgen {
19 template <
typename Node>
20 class render_graph_node :
public Node {
25 render_graph_node<Node>& connect(
string_view inp_name, output_intf& out) {
26 if(
auto inp = this->input_by_name(inp_name)) {
27 connect_output_to_input(out, inp);
32 render_graph_node<Node>&
34 if(oidx < out_node.output_count()) {
35 return connect(inp_name, out_node.output(oidx));
40 render_graph_node<Node>& connect(
string_view inp_name, node_intf& out_node) {
41 return connect(inp_name, out_node, 0);
44 render_graph_node<Node>& connect(
span_size_t iidx, output_intf& out) {
45 if(iidx < this->input_count()) {
46 connect_output_to_input(out, this->input(iidx));
51 render_graph_node<Node>&
53 if(oidx < out_node.output_count()) {
54 return connect(iidx, out_node.output(oidx));
59 render_graph_node<Node>& connect(
span_size_t iidx, node_intf& out_node) {
60 return connect(iidx, out_node, 0);
63 render_graph_node<Node>& connect(output_intf& out) {
64 return connect(0, out);
67 render_graph_node<Node>& connect(node_intf& out_node) {
68 return connect(0, out_node);
74 using _node_ptr_t = std::unique_ptr<node_intf>;
75 std::vector<_node_ptr_t> _anon_nodes;
76 std::map<std::string, _node_ptr_t> _nodes;
77 std::unique_ptr<render_node> _render_node;
81 render_graph(render_graph&&) noexcept = default;
82 render_graph(const render_graph&) = delete;
83 render_graph& operator=(render_graph&&) noexcept = default;
84 render_graph& operator=(const render_graph&) = delete;
87 void disconnect_all();
89 void add_anonymous_node(std::unique_ptr<node_intf>&&);
91 void add_node(std::
string name, std::unique_ptr<node_intf>&&);
93 template <typename NodeType, typename... P>
94 render_graph_node<NodeType>& add_new_anon(P&&... p) {
95 auto* ptr =
new render_graph_node<NodeType>(std::forward<P>(p)...);
97 add_anonymous_node(_node_ptr_t(ptr));
101 template <
typename NodeType,
typename... P>
102 render_graph_node<NodeType>& add_new(std::string name, P&&... p) {
103 auto* ptr =
new render_graph_node<NodeType>(std::forward<P>(p)...);
105 add_node(std::move(name), _node_ptr_t(ptr));
109 render_node& renderer();
112 const valid_if_positive<int>& w,
113 const valid_if_positive<int>& h);
118 optional_reference_wrapper<node_intf>
119 find_node(
const std::string& node_name);
122 optional_reference_wrapper<input_intf>
123 find_node_input(node_intf& node,
span_size_t index);
125 optional_reference_wrapper<output_intf>
126 find_node_output(node_intf& node,
span_size_t index);
128 optional_reference_wrapper<input_intf>
129 find_node_input(node_intf& node,
string_view iname);
131 optional_reference_wrapper<output_intf>
132 find_node_output(node_intf& node,
string_view oname);
134 optional_reference_wrapper<input_intf>
135 find_node_input(
const std::string& node_name,
span_size_t index);
137 optional_reference_wrapper<output_intf>
138 find_node_output(
const std::string& node_name,
span_size_t index);
140 optional_reference_wrapper<input_intf>
141 find_node_input(
const std::string& node_name,
string_view iname);
143 optional_reference_wrapper<output_intf>
144 find_node_output(
const std::string& node_name,
string_view oname);
147 bool connect_to_renderer(output_intf& output);
149 bool connect_to_renderer(node_intf&,
span_size_t index = 0);
151 bool connect_to_renderer(
const std::string& node_name,
span_size_t index);
153 bool connect_to_renderer(
const std::string& node_name) {
154 return connect_to_renderer(node_name, 0);
158 bool connect(output_intf& out, input_intf& inp);
161 node_intf& output_node,
163 node_intf& input_node,
167 node_intf& output_node,
169 node_intf& input_node,
173 connect(node_intf& output_node, node_intf& input_node,
string_view iname);
176 const std::string& output_node_name,
178 const std::string& input_node_name,
182 const std::string& output_node_name,
183 const std::string& input_node_name,
187 const std::string& output_node_name,
189 const std::string& input_node_name,
193 const std::string& output_node_name,
194 const std::string& input_node_name,
198 const std::string& output_node_name,
199 const std::string& input_node_name);
206 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
207 #include <oglplus/texgen/render_graph.inl>
210 #endif // OGLPLUS_TEXGEN_RENDER_GRAPH_HPP