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
120 void materialChange() noexcept
121 {
122 materialChanged.fetch_add(1, std::memory_order_release);
123 }
124 bool hasMaterialChanged(int64_t& renderer) const noexcept
125 {
126 int64_t res = materialChanged.load(std::memory_order_acquire);
127 if(renderer != res)
128 {
129 renderer = res;
130 return true;
131 }
132 return false;
133 }
134 std::atomic_int64_t materialChanged{0};
135
139 void geometryChange() noexcept
140 {
141 geometryChanged.fetch_add(1, std::memory_order_release);
142 }
143 bool hasGeometryChanged(int64_t& renderer) const noexcept
144 {
145 int64_t res = geometryChanged.load(std::memory_order_acquire);
146 if(renderer != res)
147 {
148 renderer = res;
149 return true;
150 }
151 return false;
152 }
153 std::atomic_int64_t geometryChanged{-1};
154
158 void renderTargetChange() noexcept
159 {
160 renderTargetSpecChanged.fetch_add(1, std::memory_order_release);
161 }
162 bool hasRenderTargetChanged(int64_t& renderer) const noexcept
163 {
164 int64_t res = renderTargetSpecChanged.load(std::memory_order_acquire);
165 if(renderer != res)
166 {
167 renderer = res;
168 return true;
169 }
170 return false;
171 }
172 std::atomic_int64_t renderTargetSpecChanged{-1};
173
174 int32_t id = -1;
175 bool addedToGraph{};
176};
177
181class SCORE_PLUGIN_GFX_EXPORT ProcessNode : public Node
182{
183public:
184 using Node::Node;
185
191 ProcessUBO standardUBO{};
192
199 ossia::geometry_spec geometry;
200
206 ossia::flat_map<int32_t, ossia::render_target_spec> renderTargetSpecs;
207
208 void process(Message&& msg) override;
209 void process(Timings tk);
210 void process(int32_t port, const ossia::value& v);
211 void process(int32_t port, const ossia::audio_vector& v);
212 void process(int32_t port, const ossia::geometry_spec& v);
213 void process(int32_t port, const ossia::render_target_spec& v);
214 void process(int32_t port, const ossia::transform3d& v);
215 void process(int32_t port, ossia::monostate) const noexcept { }
216 void process(int32_t port, const FunctionMessage&);
217
218 QSize resolveRenderTargetSize(int32_t port, RenderList& renderer) const noexcept;
220 resolveRenderTargetSpecs(int32_t port, RenderList& renderer) const noexcept;
221};
222
226class SCORE_PLUGIN_GFX_EXPORT NodeModel : public score::gfx::ProcessNode
227{
228public:
229 explicit NodeModel();
230 virtual ~NodeModel();
231
233 createRenderer(RenderList& r) const noexcept override;
234
235protected:
236 std::unique_ptr<char[]> m_materialData;
237
238 friend class GenericNodeRenderer;
239};
240}
241
242// QDebug operator<<(QDebug, const score::gfx::gfx_input&);
243QDebug 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
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:139
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:158
void materialChange() noexcept
Used to notify a material change from the model to the renderers.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:120
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:227
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:182
ossia::geometry_spec geometry
The geometry to use.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:199
ossia::flat_map< int32_t, ossia::render_target_spec > renderTargetSpecs
Render target info.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:206
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