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/PointerState.hpp>
5#include <Gfx/Graph/RenderState.hpp>
6#include <Gfx/Graph/Uniforms.hpp>
7
8#include <score_plugin_gfx_export.h>
9
10#include <memory>
11
12namespace score::gfx
13{
14class GpuResourceRegistry;
15struct OffscreenFrame;
17{
18 GraphicsApi graphicsApi{};
19 std::function<void()> onReady;
20 std::function<void()> onResize;
21
34 std::function<void()> onReleaseRenderList;
35};
36
37class SCORE_PLUGIN_GFX_EXPORT OutputNodeRenderer : public score::gfx::NodeRenderer
38{
39public:
40 using score::gfx::NodeRenderer::NodeRenderer;
41 virtual ~OutputNodeRenderer();
42 virtual void
43 finishFrame(RenderList&, QRhiCommandBuffer& commands, QRhiResourceUpdateBatch*& res);
44
45 // Sinks have no output edges, so there is nothing to release per-edge.
46 // Concrete sinks may still override, e.g. to drop per-input bookkeeping
47 // routed through addOutputPass.
48 void removeOutputPass(RenderList&, Edge&) override { }
49};
50
51class Window;
55class SCORE_PLUGIN_GFX_EXPORT OutputNode : public score::gfx::Node
56{
57public:
58 virtual ~OutputNode();
59
60 virtual void setRenderer(std::shared_ptr<RenderList>) = 0;
61 virtual RenderList* renderer() const = 0;
62
63 OutputNodeRenderer* createRenderer(RenderList& r) const noexcept override = 0;
64
65 virtual void startRendering() = 0;
66 virtual void render() = 0;
67 virtual void stopRendering() = 0;
68 virtual bool canRender() const = 0;
69 virtual void onRendererChange() = 0;
70
77 virtual void setVSyncCallback(std::function<void()>);
78
79 virtual void createOutput(OutputConfiguration conf) = 0;
80
81 virtual void updateGraphicsAPI(GraphicsApi);
82 virtual void destroyOutput() = 0;
83 virtual std::shared_ptr<RenderState> renderState() const = 0;
84
87 bool preview{};
91 bool previewHub{};
92
94 {
95 // If set, the host is responsible for calling render() at this
96 // rate (given in milliseconds)
97 std::optional<double> manualRenderingRate;
98 bool outputNeedsRenderPass{};
99 bool supportsVSync{};
100 // The host renders this output's RenderList itself, from its own frame
101 // loop: GfxContext never calls render() on it.
102 bool hostDriven{};
103 OutputNode* parent{};
104 };
105
106 virtual Configuration configuration() const noexcept = 0;
107
127 virtual TextureRenderTarget currentRenderTarget() const noexcept { return {}; }
128
147 GpuResourceRegistry& acquireRegistry();
148
153 GpuResourceRegistry* registry() const noexcept { return m_registry.get(); }
154
167 void releaseRegistry();
168
175 virtual bool deviceLost() const noexcept { return m_deviceLost; }
176
180 void handleDeviceLost(const char* output) noexcept;
181
188 const std::shared_ptr<PointerState>& pointerState() const noexcept
189 {
190 return m_pointerState;
191 }
192
193protected:
198 bool checkDeviceLost(const OffscreenFrame& frame, QRhi& rhi, const char* output) noexcept;
199 bool checkDeviceLost(int frameOpResult, QRhi& rhi, const char* output) noexcept;
200
201 void resetDeviceLost() noexcept { m_deviceLost = false; }
202
203 explicit OutputNode();
204
213 void releaseOwnedRenderList();
214
215 // Set by concrete createOutput() implementations from
216 // OutputConfiguration::onReleaseRenderList.
217 std::function<void()> m_onReleaseRenderList;
218
219 // Persistent across RenderList rebuilds. See acquireRegistry() docs.
220 // unique_ptr is opaque-typed in this header (forward-declared above);
221 // its destructor needs the full type, hence the out-of-line ~OutputNode
222 // implementation in OutputNode.cpp.
223 std::unique_ptr<GpuResourceRegistry> m_registry;
224
225 std::shared_ptr<PointerState> m_pointerState{std::make_shared<PointerState>()};
226
227 bool m_deviceLost{};
228};
229
231enum class OutputDepth
232{
233 None,
235 Texture,
238};
239
260SCORE_PLUGIN_GFX_EXPORT
261TextureRenderTarget createOutputRenderTarget(
262 RenderState& state, QRhiTexture& texture, OutputDepth depth = OutputDepth::None,
263 int samples = 0);
264
272SCORE_PLUGIN_GFX_EXPORT
274 RenderState& state, TextureRenderTarget& target, bool deferred = false) noexcept;
275}
Per-RenderList arena store for GPU-resident scene data.
Definition GpuResourceRegistry.hpp:45
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:115
Renderer for a given node.
Definition NodeRenderer.hpp:11
Base class for sink nodes (QWindow, spout, syphon, NDI output, ...)
Definition OutputNode.hpp:56
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:153
virtual bool deviceLost() const noexcept
True once the output's graphics device was reported lost.
Definition OutputNode.hpp:175
const std::shared_ptr< PointerState > & pointerState() const noexcept
The mouse and touch points over this output, decoded from the window's events into vertexshaderart's ...
Definition OutputNode.hpp:188
Definition OutputNode.hpp:38
void removeOutputPass(RenderList &, Edge &) override
Definition OutputNode.hpp:48
List of nodes to be rendered to an output.
Definition RenderList.hpp:36
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
TextureRenderTarget createOutputRenderTarget(RenderState &state, QRhiTexture &texture, OutputDepth depth, int samples)
The render target an offscreen output's input is drawn into.
Definition OutputNode.cpp:338
OutputDepth
The depth attachment of an output's render target.
Definition OutputNode.hpp:232
@ DepthStencil
Depth-stencil render buffer, as a window's swap chain has.
@ Texture
D32F texture, the format reverse-Z wants.
GraphicsApi
Available graphics APIs to use.
Definition RenderState.hpp:25
void releaseOutputRenderTarget(RenderState &state, TextureRenderTarget &target, bool deferred) noexcept
Frees what createOutputRenderTarget allocated, but not the texture.
Definition OutputNode.cpp:374
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:236
RAII bracket for QRhi::beginOffscreenFrame / endOffscreenFrame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:54
Definition OutputNode.hpp:17
std::function< void()> onReleaseRenderList
Ask the owning Graph to release + deregister the RenderList that was built against this output's QRhi...
Definition OutputNode.hpp:34
Definition OutputNode.hpp:94
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:307