OGLplus  (0.59.0) a C++ wrapper for rendering APIs

interface.hpp
Go to the documentation of this file.
1 #ifndef OGLPLUS_TEXGEN_INTERFACE_HPP
9 #define OGLPLUS_TEXGEN_INTERFACE_HPP
10 
11 #include "data_type.hpp"
12 #include "render_params.hpp"
13 #include <eagine/assert.hpp>
14 #include <eagine/interface.hpp>
15 #include <eagine/optional_ref.hpp>
16 #include <eagine/types.hpp>
18 #include <cstddef>
19 #include <iosfwd>
20 #include <memory>
21 
22 namespace eagine::oglp::texgen {
23 
24 struct constant_intf;
25 struct input_intf;
26 struct output_intf;
27 struct node_intf;
28 
29 class compile_context_impl;
30 
31 class compile_context {
32 private:
33  std::unique_ptr<compile_context_impl> _pimpl;
34 
35  const compile_context_impl& _impl() const noexcept;
36 
37  compile_context_impl& _impl() noexcept;
38 
39 public:
40  compile_context();
41  compile_context(compile_context&&) noexcept = default;
42  compile_context(const compile_context&) = delete;
43  compile_context& operator=(compile_context&&) = delete;
44  compile_context& operator=(const compile_context&) = delete;
45  ~compile_context() noexcept;
46 
47  unsigned glsl_version() const;
48 
49  void add_tag(string_view tag);
50  bool has_tag(string_view tag) const noexcept;
51 
52  void remember_constant(const constant_intf&);
53  bool remembers_constant(const constant_intf&) const noexcept;
54 
55  void remember_output(const output_intf&);
56  bool remembers_output(const output_intf&) const noexcept;
57 };
58 
59 struct constant_intf : interface<constant_intf> {
60 
61  virtual string_view name() const noexcept = 0;
62 
63  virtual slot_data_type value_type() = 0;
64 
65  virtual std::ostream& definitions(std::ostream&, compile_context&) = 0;
66 
67  virtual std::ostream& expression(std::ostream&, compile_context&) = 0;
68 };
69 
70 struct input_intf : interface<input_intf> {
71 
72  virtual string_view name() noexcept = 0;
73 
74  virtual bool accepts_value_type(slot_data_type) = 0;
75 
76  virtual std::ostream& definitions(std::ostream&, compile_context&) = 0;
77 
78  virtual std::ostream& expression(std::ostream&, compile_context&) = 0;
79 
80  virtual bool is_connected() = 0;
81 
82  virtual bool is_connected(output_intf&) = 0;
83 
84  virtual bool can_connect(output_intf&) = 0;
85 
86  virtual bool connect(output_intf&) = 0;
87 
88  virtual void disconnect() = 0;
89 
90  virtual bool disconnect(output_intf&) = 0;
91 
92  virtual output_intf& connected_output() = 0;
93 
94  virtual bool
95  set_default_value(valid_if_between<span_size_t, 0, 3> c, float v) = 0;
96 
97  bool set_default(float x) {
98  return set_default_value(0, x);
99  }
100 
101  bool set_default(float x, float y) {
102  return set_default_value(0, x) && set_default_value(1, y);
103  }
104 
105  bool set_default(float x, float y, float z) {
106  return set_default_value(0, x) && set_default_value(1, y) &&
107  set_default_value(2, z);
108  }
109 
110  bool set_default(float x, float y, float z, float w) {
111  return set_default_value(0, x) && set_default_value(1, y) &&
112  set_default_value(3, z) && set_default_value(4, w);
113  }
114 
115  virtual void update_needed() = 0;
116 
117  virtual void prepare_connected() = 0;
118 
119  virtual bool render_connected(const render_params&) = 0;
120 };
121 
122 struct output_intf : interface<output_intf> {
123 
124  virtual string_view name() noexcept = 0;
125 
126  virtual slot_data_type value_type() = 0;
127 
128  virtual render_param_bits required_params() = 0;
129 
130  virtual bool needs_params() {
131  return bool(required_params());
132  }
133 
134  virtual std::ostream& definitions(std::ostream&, compile_context&) = 0;
135 
136  virtual std::ostream& expression(std::ostream&, compile_context&) = 0;
137 
138  virtual bool is_connected(input_intf&) = 0;
139 
140  virtual bool connect(input_intf&) = 0;
141 
142  virtual bool disconnect(input_intf&) = 0;
143 
144  virtual void disconnect_all() = 0;
145 
146  virtual void notify_connected() = 0;
147 
148  virtual void prepare_parent() = 0;
149 
150  virtual bool render_parent(const render_params&) = 0;
151 };
152 
153 bool connect_output_to_input(output_intf& output, input_intf& input);
154 bool disconnect_output_from_input(output_intf& output, input_intf& input);
155 
156 struct node_intf : interface<node_intf> {
157 
158  virtual span_size_t input_count() = 0;
159 
160  virtual input_intf& input(span_size_t) = 0;
161 
162  virtual optional_reference_wrapper<input_intf> input_by_name(string_view);
163 
164  virtual bool can_add_input() = 0;
165 
166  virtual input_intf& add_input(string_view) = 0;
167 
168  std::ostream& input_definitions(std::ostream&, compile_context&);
169 
170  virtual span_size_t output_count() = 0;
171 
172  virtual output_intf& output(span_size_t) = 0;
173 
174  virtual optional_reference_wrapper<output_intf> output_by_name(string_view);
175 
176  void disconnect_all();
177 
178  virtual string_view type_name() = 0;
179 
180  virtual void update_needed() = 0;
181 
182  virtual void prepare() = 0;
183 
184  virtual bool render(const render_params&) = 0;
185 };
186 
187 class input_slot;
188 class output_slot;
189 
190 class input_slot {
191 private:
192  friend class output_slot;
193  input_intf* _pimpl;
194 
195  input_intf& _impl() noexcept {
196  EAGINE_ASSERT(is_valid());
197  return *_pimpl;
198  }
199 
200  const input_intf& _impl() const noexcept {
201  EAGINE_ASSERT(is_valid());
202  return *_pimpl;
203  }
204 
205 public:
206  input_slot() = default;
207 
208  input_slot(input_intf& impl)
209  : _pimpl(&impl) {}
210 
211  bool is_valid() const noexcept {
212  return _pimpl != nullptr;
213  }
214 
215  explicit inline operator bool() const noexcept {
216  return is_valid();
217  }
218 
219  friend bool operator==(const input_slot& a, const input_slot& b) noexcept {
220  return a.is_valid() && b.is_valid() && (a._pimpl == b._pimpl);
221  }
222 
223  friend bool operator!=(const input_slot& a, const input_slot& b) noexcept {
224  return a.is_valid() && b.is_valid() && (a._pimpl != b._pimpl);
225  }
226 
227  friend bool operator<(const input_slot& a, const input_slot& b) noexcept {
228  return a.is_valid() && b.is_valid() && (a._pimpl < b._pimpl);
229  }
230 
231  string_view name() noexcept {
232  return _impl().name();
233  }
234 
235  bool accepts_value_type(slot_data_type type) {
236  return _impl().accepts_value_type(type);
237  }
238 
239  bool is_connected(output_slot& output);
240 
241  bool connect(output_slot& output);
242  bool disconnect(output_slot& output);
243 };
244 
245 class output_slot {
246 private:
247  friend class input_slot;
248  output_intf* _pimpl;
249 
250  output_intf& _impl() noexcept {
251  EAGINE_ASSERT(is_valid());
252  return *_pimpl;
253  }
254 
255 public:
256  output_slot() = default;
257 
258  output_slot(output_intf& impl)
259  : _pimpl(&impl) {}
260 
261  bool is_valid() const noexcept {
262  return _pimpl != nullptr;
263  }
264 
265  explicit inline operator bool() const noexcept {
266  return is_valid();
267  }
268 
269  friend bool operator==(const output_slot& a, const output_slot& b) noexcept {
270  return a.is_valid() && b.is_valid() && (a._pimpl == b._pimpl);
271  }
272 
273  friend bool operator!=(const output_slot& a, const output_slot& b) noexcept {
274  return a.is_valid() && b.is_valid() && (a._pimpl != b._pimpl);
275  }
276 
277  friend bool operator<(const output_slot& a, const output_slot& b) noexcept {
278  return a.is_valid() && b.is_valid() && (a._pimpl < b._pimpl);
279  }
280 
281  string_view name() noexcept {
282  return _impl().name();
283  }
284 
285  slot_data_type value_type() {
286  return _impl().value_type();
287  }
288 
289  std::ostream& definitions(std::ostream& out, compile_context& ctxt) {
290  return _impl().definitions(out, ctxt);
291  }
292 
293  std::ostream& expression(std::ostream& out, compile_context& ctxt) {
294  return _impl().expression(out, ctxt);
295  }
296 
297  bool is_connected(input_slot&);
298 
299  bool connect(input_slot&);
300  bool disconnect(input_slot&);
301 
302  void notify_connected() {
303  _impl().notify_connected();
304  }
305 };
306 
307 } // namespace eagine::oglp::texgen
308 
309 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
310 #include <oglplus/texgen/interface.inl>
311 #endif
312 
313 #endif // OGLPLUS_TEXGEN_INTERFACE_HPP
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
static auto type_name(const T &) noexcept -> std::string
Returns the demangled name for type T.
Definition: type_name.hpp:24
static constexpr auto operator!=(const valid_if< T, P1 > &v1, const valid_if< T, P2 > &v2) noexcept -> tribool
Non-equality comparison of two conditionally valid values.
Definition: decl.hpp:169
auto operator==(message_id l, static_message_id< ClassId, MethodId > r) noexcept
Equality comparison between message_id and static_message_id.
Definition: message_id.hpp:131
valid_if_between_c< T, T, Min, Max > valid_if_between
Specialization of valid_if, for values valid if between Min and Max.
Definition: between.hpp:53
static constexpr auto operator<(const valid_if< T, P1 > &v1, const valid_if< T, P2 > &v2) noexcept -> tribool
Less-than comparison of two conditionally valid values.
Definition: decl.hpp:180

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).