Loading...
Searching...
No Matches
score-plugin-gfx/Gfx/Graph/Node.hpp
1#pragma once
2#include <Gfx/Graph/CommonUBOs.hpp>
3#include <Gfx/Graph/Mesh.hpp>
4#include <Gfx/Graph/RenderState.hpp>
5#include <Gfx/Graph/Uniforms.hpp>
6#include <Gfx/Graph/Utils.hpp>
7
8#include <ossia/dataflow/geometry_port.hpp>
9#include <ossia/dataflow/nodes/media.hpp>
10#include <ossia/dataflow/texture_port.hpp>
11#include <ossia/dataflow/token_request.hpp>
12#include <ossia/detail/flat_map.hpp>
13#include <ossia/detail/variant.hpp>
14#include <ossia/network/value/value.hpp>
15
16#include <score_plugin_gfx_export.h>
17
18#include <vector>
19
20namespace score::gfx
21{
22class RenderList;
23struct Graph;
24class GenericNodeRenderer;
25class NodeRenderer;
26using FunctionMessage = std::function<void(score::gfx::Node&)>;
27#if BOOST_VERSION < 107900
28// Old boost: small_vector was not nothrow-move-constructible so we remove the check there.
29using gfx_input = ossia::slow_variant<
30 ossia::monostate, ossia::value, ossia::audio_vector, ossia::render_target_spec,
31 ossia::geometry_spec, ossia::transform3d, FunctionMessage>;
32#else
33using gfx_input = ossia::variant<
34 ossia::monostate, ossia::value, ossia::audio_vector, ossia::render_target_spec,
35 ossia::geometry_spec, ossia::transform3d, FunctionMessage>;
36#endif
37
43struct Timings
44{
45 ossia::time_value date{};
46 ossia::time_value parent_duration{};
47};
48
49struct Message
50{
51 int32_t node_id{};
52 Timings token{};
53 std::vector<gfx_input> input;
54};
55
57{
58 QSize size;
59
60 QRhiTexture::Format format = QRhiTexture::Format ::RGBA8;
61
62 QRhiSampler::Filter mag_filter = QRhiSampler::Linear;
63 QRhiSampler::Filter min_filter = QRhiSampler::Linear;
64 QRhiSampler::Filter mipmap_mode = QRhiSampler::None;
65
66 QRhiSampler::AddressMode address_u = QRhiSampler::Repeat;
67 QRhiSampler::AddressMode address_v = QRhiSampler::Repeat;
68 QRhiSampler::AddressMode address_w = QRhiSampler::Repeat;
69};
70
74class SCORE_PLUGIN_GFX_EXPORT Node
75{
76public:
77 explicit Node();
78 virtual ~Node();
79
80 Node(const Node&) = delete;
81 Node(Node&&) = delete;
82 Node& operator=(const Node&) = delete;
83 Node& operator=(Node&&) = delete;
84
88 virtual NodeRenderer* createRenderer(RenderList& r) const noexcept = 0;
89
93 virtual void renderedNodesChanged();
94
98 virtual void process(Message&& msg);
99 virtual void update();
100
104 std::vector<Port*> input;
110 ossia::small_pod_vector<Port*, 1> output;
111
115 ossia::flat_map<RenderList*, score::gfx::NodeRenderer*> renderedNodes;
116
122 ossia::flat_map<int32_t, ossia::render_target_spec> renderTargetSpecs;
123
127 void materialChange() noexcept
128 {
129 materialChanged.fetch_add(1, std::memory_order_release);
130 }
131 bool hasMaterialChanged(int64_t& renderer) const noexcept
132 {
133 int64_t res = materialChanged.load(std::memory_order_acquire);
134 if(renderer != res)
135 {
136 renderer = res;
137 return true;
138 }
139 return false;
140 }
141 std::atomic_int64_t materialChanged{0};
142
146 void geometryChange() noexcept
147 {
148 geometryChanged.fetch_add(1, std::memory_order_release);
149 }
150 bool hasGeometryChanged(int64_t& renderer) const noexcept
151 {
152 int64_t res = geometryChanged.load(std::memory_order_acquire);
153 if(renderer != res)
154 {
155 renderer = res;
156 return true;
157 }
158 return false;
159 }
160 std::atomic_int64_t geometryChanged{-1};
161
165 void renderTargetChange() noexcept
166 {
167 renderTargetSpecChanged.fetch_add(1, std::memory_order_release);
168 }
169 bool hasRenderTargetChanged(int64_t& renderer) const noexcept
170 {
171 int64_t res = renderTargetSpecChanged.load(std::memory_order_acquire);
172 if(renderer != res)
173 {
174 renderer = res;
175 return true;
176 }
177 return false;
178 }
179 std::atomic_int64_t renderTargetSpecChanged{-1};
180
181 int32_t id = -1;
182 bool requiresDepth{};
183 bool addedToGraph{};
184
185 QSize resolveRenderTargetSize(int32_t port, RenderList& renderer) const noexcept;
186 RenderTargetSpecs
187 resolveRenderTargetSpecs(int32_t port, RenderList& renderer) const noexcept;
188
189 void process(int32_t port, const ossia::render_target_spec& v);
190};
191
195class SCORE_PLUGIN_GFX_EXPORT ProcessNode : public Node
196{
197public:
198 using Node::Node;
199
205 ProcessUBO standardUBO{};
206
213 ossia::geometry_spec geometry;
214
215 void process(Message&& msg) override;
216 void process(Timings tk);
217 void process(int32_t port, const ossia::value& v);
218 void process(int32_t port, const ossia::audio_vector& v);
219 void process(int32_t port, const ossia::geometry_spec& v);
220 void process(int32_t port, const ossia::transform3d& v);
221 void process(int32_t port, ossia::monostate) const noexcept { }
222 void process(int32_t port, const FunctionMessage&);
223 using Node::process;
224};
225
229class SCORE_PLUGIN_GFX_EXPORT NodeModel : public score::gfx::ProcessNode
230{
231public:
232 explicit NodeModel();
233 virtual ~NodeModel();
234
236 createRenderer(RenderList& r) const noexcept override;
237
238protected:
239 std::unique_ptr<char[]> m_materialData;
240
241 friend class GenericNodeRenderer;
242};
243}
244
245// QDebug operator<<(QDebug, const score::gfx::gfx_input&);
246QDebug operator<<(QDebug, const std::vector<score::gfx::gfx_input>&);
Generic renderer.
Definition NodeRenderer.hpp:84
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:75
ossia::flat_map< int32_t, ossia::render_target_spec > renderTargetSpecs
Render target info.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:122
std::vector< Port * > input
Input ports of that node.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:104
void geometryChange() noexcept
Used to notify a geometry change from the model to the renderers.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:146
void renderTargetChange() noexcept
Used to notify a render target (texture inlet) change from the model to the renderers.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:165
void materialChange() noexcept
Used to notify a material change from the model to the renderers.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:127
ossia::flat_map< RenderList *, score::gfx::NodeRenderer * > renderedNodes
Map associating each RenderList to a Renderer for this model.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:115
virtual NodeRenderer * createRenderer(RenderList &r) const noexcept=0
Create a renderer in a given context for this node.
ossia::small_pod_vector< Port *, 1 > output
Output ports of that node.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:110
Common base class for most single-pass, simple nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:230
Renderer for a given node.
Definition NodeRenderer.hpp:11
Common base class for nodes that map to score processes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:196
ossia::geometry_spec geometry
The geometry to use.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:213
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:50
UBO specific to individual processes / nodes.
Definition CommonUBOs.hpp:12
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:57
Messages sent from the execution thread to the rendering thread.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:44