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 <boost/version.hpp>
19#include <vector>
20
21namespace score::gfx
22{
23class RenderList;
24struct Graph;
25class GenericNodeRenderer;
26class NodeRenderer;
27using FunctionMessage = std::function<void(score::gfx::Node&)>;
28#if BOOST_VERSION < 107900
29#define a <::BOOST_VERSION>
30#include a
31#error Boost version not supported anymore
32#endif
33using gfx_input = ossia::variant<
34 ossia::monostate, ossia::value, ossia::audio_vector, ossia::render_target_spec,
35 ossia::transform3d, FunctionMessage, ossia::buffer_spec>;
36
42struct Timings
43{
44 ossia::time_value date{};
45 ossia::time_value parent_duration{};
46};
47
48struct Message
49{
50 int32_t node_id{};
51 Timings token{};
52 std::vector<gfx_input> input;
53};
54
56{
57 QSize size;
58
59 QRhiTexture::Format format = QRhiTexture::Format ::RGBA8;
60
61 QRhiSampler::Filter mag_filter = QRhiSampler::Linear;
62 QRhiSampler::Filter min_filter = QRhiSampler::Linear;
63 QRhiSampler::Filter mipmap_mode = QRhiSampler::None;
64
65 QRhiSampler::AddressMode address_u = QRhiSampler::Repeat;
66 QRhiSampler::AddressMode address_v = QRhiSampler::Repeat;
67 QRhiSampler::AddressMode address_w = QRhiSampler::Repeat;
68};
69
73class SCORE_PLUGIN_GFX_EXPORT Node : public QObject
74{
75public:
76 explicit Node();
77 virtual ~Node();
78
79 Node(const Node&) = delete;
80 Node(Node&&) = delete;
81 Node& operator=(const Node&) = delete;
82 Node& operator=(Node&&) = delete;
83
87 virtual NodeRenderer* createRenderer(RenderList& r) const noexcept = 0;
88
92 virtual void renderedNodesChanged();
93
97 virtual void process(Message&& msg);
98 virtual void update();
99
103 std::vector<Port*> input;
109 ossia::small_pod_vector<Port*, 1> output;
110
114 ossia::flat_map<RenderList*, score::gfx::NodeRenderer*> renderedNodes;
115
121 ossia::flat_map<int32_t, ossia::render_target_spec> renderTargetSpecs;
122
126 void materialChange() noexcept
127 {
128 materialChanged.fetch_add(1, std::memory_order_release);
129 }
130 bool hasMaterialChanged(int64_t& renderer) const noexcept
131 {
132 int64_t res = materialChanged.load(std::memory_order_acquire);
133 if(renderer != res)
134 {
135 renderer = res;
136 return true;
137 }
138 return false;
139 }
140 std::atomic_int64_t materialChanged{0};
141
145 void renderTargetChange() noexcept
146 {
147 renderTargetSpecChanged.fetch_add(1, std::memory_order_release);
148 }
149 bool hasRenderTargetChanged(int64_t& renderer) const noexcept
150 {
151 int64_t res = renderTargetSpecChanged.load(std::memory_order_acquire);
152 if(renderer != res)
153 {
154 renderer = res;
155 return true;
156 }
157 return false;
158 }
159 std::atomic_int64_t renderTargetSpecChanged{-1};
160
161 int32_t nodeId = -1;
162 bool requiresDepth{};
163 bool addedToGraph{};
164
165 QSize resolveRenderTargetSize(int32_t port, RenderList& renderer) const noexcept;
166 RenderTargetSpecs
167 resolveRenderTargetSpecs(int32_t port, RenderList& renderer) const noexcept;
168
169 void process(int32_t port, const ossia::render_target_spec& v);
170};
171
175class SCORE_PLUGIN_GFX_EXPORT ProcessNode : public Node
176{
177public:
178 using Node::Node;
179
185 ProcessUBO standardUBO{};
186
187 void process(Message&& msg) override;
188 virtual void process(Timings tk);
189 virtual void process(int32_t port, const ossia::value& v);
190 virtual void process(int32_t port, const ossia::audio_vector& v);
191 // virtual void process(int32_t port, const ossia::geometry_spec& v);
192 virtual void process(int32_t port, const ossia::transform3d& v);
193 void process(int32_t port, ossia::monostate) const noexcept { }
194 virtual void process(int32_t port, const FunctionMessage&);
195 virtual void process(int32_t port, const ossia::buffer_spec&);
196 using Node::process;
197};
198
202class SCORE_PLUGIN_GFX_EXPORT NodeModel : public score::gfx::ProcessNode
203{
204public:
205 explicit NodeModel();
206 virtual ~NodeModel();
207
209 createRenderer(RenderList& r) const noexcept override;
210
211protected:
212 std::unique_ptr<char[]> m_materialData;
213
214 friend class GenericNodeRenderer;
215};
216}
217
218// QDebug operator<<(QDebug, const score::gfx::gfx_input&);
219QDebug operator<<(QDebug, const std::vector<score::gfx::gfx_input>&);
Generic renderer.
Definition NodeRenderer.hpp:96
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:74
ossia::flat_map< int32_t, ossia::render_target_spec > renderTargetSpecs
Render target info.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:121
std::vector< Port * > input
Input ports of that node.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:103
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:145
void materialChange() noexcept
Used to notify a material change from the model to the renderers.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:126
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:114
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:109
Common base class for most single-pass, simple nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:203
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:176
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:49
UBO specific to individual processes / nodes.
Definition CommonUBOs.hpp:12
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:56
Messages sent from the execution thread to the rendering thread.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:43