Loading...
Searching...
No Matches
OutputNode.hpp
1#pragma once
2#include <Gfx/Graph/Node.hpp>
3#include <Gfx/Graph/NodeRenderer.hpp>
4#include <Gfx/Graph/RenderState.hpp>
5#include <Gfx/Graph/Uniforms.hpp>
6
7#include <score_plugin_gfx_export.h>
8
9#include <memory>
10
11namespace score::gfx
12{
13class GpuResourceRegistry;
14struct OffscreenFrame;
16{
17 GraphicsApi graphicsApi{};
18 std::function<void()> onReady;
19 std::function<void()> onResize;
20
33 std::function<void()> onReleaseRenderList;
34};
35
36class SCORE_PLUGIN_GFX_EXPORT OutputNodeRenderer : public score::gfx::NodeRenderer
37{
38public:
39 using score::gfx::NodeRenderer::NodeRenderer;
40 virtual ~OutputNodeRenderer();
41 virtual void
42 finishFrame(RenderList&, QRhiCommandBuffer& commands, QRhiResourceUpdateBatch*& res);
43
44 // Sinks have no output edges, so there is nothing to release per-edge.
45 // Concrete sinks may still override, e.g. to drop per-input bookkeeping
46 // routed through addOutputPass.
47 void removeOutputPass(RenderList&, Edge&) override { }
48};
49
50class Window;
54class SCORE_PLUGIN_GFX_EXPORT OutputNode : public score::gfx::Node
55{
56public:
57 virtual ~OutputNode();
58
59 virtual void setRenderer(std::shared_ptr<RenderList>) = 0;
60 virtual RenderList* renderer() const = 0;
61
62 OutputNodeRenderer* createRenderer(RenderList& r) const noexcept override = 0;
63
64 virtual void startRendering() = 0;
65 virtual void render() = 0;
66 virtual void stopRendering() = 0;
67 virtual bool canRender() const = 0;
68 virtual void onRendererChange() = 0;
69
76 virtual void setVSyncCallback(std::function<void()>);
77
78 virtual void createOutput(OutputConfiguration conf) = 0;
79
80 virtual void updateGraphicsAPI(GraphicsApi);
81 virtual void destroyOutput() = 0;
82 virtual std::shared_ptr<RenderState> renderState() const = 0;
83
85 {
86 // If set, the host is responsible for calling render() at this
87 // rate (given in milliseconds)
88 std::optional<double> manualRenderingRate;
89 bool outputNeedsRenderPass{};
90 bool supportsVSync{};
91 // The host renders this output's RenderList itself, from its own frame
92 // loop: GfxContext never calls render() on it.
93 bool hostDriven{};
94 OutputNode* parent{};
95 };
96
97 virtual Configuration configuration() const noexcept = 0;
98
118 virtual TextureRenderTarget currentRenderTarget() const noexcept { return {}; }
119
138 GpuResourceRegistry& acquireRegistry();
139
144 GpuResourceRegistry* registry() const noexcept { return m_registry.get(); }
145
158 void releaseRegistry();
159
166 virtual bool deviceLost() const noexcept { return m_deviceLost; }
167
171 void handleDeviceLost(const char* output) noexcept;
172
173protected:
178 bool checkDeviceLost(const OffscreenFrame& frame, QRhi& rhi, const char* output) noexcept;
179 bool checkDeviceLost(int frameOpResult, QRhi& rhi, const char* output) noexcept;
180
181 void resetDeviceLost() noexcept { m_deviceLost = false; }
182
183 explicit OutputNode();
184
193 void releaseOwnedRenderList();
194
195 // Set by concrete createOutput() implementations from
196 // OutputConfiguration::onReleaseRenderList.
197 std::function<void()> m_onReleaseRenderList;
198
199 // Persistent across RenderList rebuilds. See acquireRegistry() docs.
200 // unique_ptr is opaque-typed in this header (forward-declared above);
201 // its destructor needs the full type, hence the out-of-line ~OutputNode
202 // implementation in OutputNode.cpp.
203 std::unique_ptr<GpuResourceRegistry> m_registry;
204
205 bool m_deviceLost{};
206};
207}
Per-RenderList arena store for GPU-resident scene data.
Definition GpuResourceRegistry.hpp:44
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:76
Renderer for a given node.
Definition NodeRenderer.hpp:11
Base class for sink nodes (QWindow, spout, syphon, NDI output, ...)
Definition OutputNode.hpp:55
OutputNodeRenderer * createRenderer(RenderList &r) const noexcept override=0
Create a renderer in a given context for this node.
GpuResourceRegistry * registry() const noexcept
Non-owning accessor. Returns null if no registry has been acquired yet (e.g. queried before the first...
Definition OutputNode.hpp:144
virtual bool deviceLost() const noexcept
True once the output's graphics device was reported lost.
Definition OutputNode.hpp:166
Definition OutputNode.hpp:37
void removeOutputPass(RenderList &, Edge &) override
Definition OutputNode.hpp:47
List of nodes to be rendered to an output.
Definition RenderList.hpp:33
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
GraphicsApi
Available graphics APIs to use.
Definition RenderState.hpp:22
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:220
RAII bracket for QRhi::beginOffscreenFrame / endOffscreenFrame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:49
Definition OutputNode.hpp:16
std::function< void()> onReleaseRenderList
Ask the owning Graph to release + deregister the RenderList that was built against this output's QRhi...
Definition OutputNode.hpp:33
Definition OutputNode.hpp:85
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:279