Loading...
Searching...
No Matches
MultiWindowNode.hpp
1#pragma once
2#include <Gfx/Graph/OutputNode.hpp>
3#include <Gfx/Graph/Utils.hpp>
4#include <Gfx/WindowDevice.hpp>
5
6namespace score::gfx
7{
8class Window;
9
10struct SCORE_PLUGIN_GFX_EXPORT MultiWindowNode : OutputNode
11{
12 explicit MultiWindowNode(
13 Configuration conf, const std::vector<Gfx::OutputMapping>& mappings);
14 virtual ~MultiWindowNode();
15
16 void startRendering() override;
17 void render() override;
18 void onRendererChange() override;
19 bool canRender() const override;
20 void stopRendering() override;
21
22 void setRenderer(std::shared_ptr<RenderList> r) override;
23 RenderList* renderer() const override;
24
25 void createOutput(score::gfx::OutputConfiguration) override;
26 void destroyOutput() override;
27 void updateGraphicsAPI(GraphicsApi) override;
28 void setVSyncCallback(std::function<void()>) override;
29
30 std::shared_ptr<RenderState> renderState() const override;
31 score::gfx::OutputNodeRenderer* createRenderer(RenderList& r) const noexcept override;
32 Configuration configuration() const noexcept override;
33
35 {
36 float width{0.0f};
37 float gamma{2.2f};
38 };
39
41 {
42 std::shared_ptr<Window> window;
43 QRhiSwapChain* swapChain{};
44 QRhiRenderBuffer* depthStencil{};
45 QRhiRenderPassDescriptor* renderPassDescriptor{};
46 QRectF sourceRect{0, 0, 1, 1};
47 bool hasSwapChain{};
48
49 EdgeBlendData blendLeft, blendRight, blendTop, blendBottom;
50
51 Gfx::CornerWarp cornerWarp;
52
53 int rotation{0};
54 bool mirrorX{false};
55 bool mirrorY{false};
56 };
57
58 const std::vector<WindowOutput>& windowOutputs() const noexcept
59 {
60 return m_windowOutputs;
61 }
62
63 // Stable offscreen render target used as the input target for the upstream
64 // graph. Owned by the node so it exists independently of any window being
65 // ready. Every upstream pipeline renders into this target; the per-window
66 // blit pipelines sample from it.
67 const TextureRenderTarget& offscreenTarget() const noexcept
68 {
69 return m_offscreenTarget;
70 }
71
72 void setRenderSize(QSize sz);
73 void setSourceRect(int windowIndex, QRectF rect);
74 void setEdgeBlend(int windowIndex, int side, float width, float gamma);
75 void setCornerWarp(int windowIndex, const Gfx::CornerWarp& warp);
76 void setTransform(int windowIndex, int rotation, bool mirrorX, bool mirrorY);
77 void setSwapchainFlag(Gfx::SwapchainFlag flag);
78 void setSwapchainFormat(Gfx::SwapchainFormat format);
79
80 std::function<void(float)> onFps;
81 // Called once all windows have been constructed in createOutput(),
82 // before any of them has a swap chain. Used by multiwindow_device to
83 // connect Qt signals.
84 std::function<void()> onWindowsCreated;
85
86private:
87 void renderBlack();
88 // Per-window swap chain init / release. Idempotent and safe to call
89 // multiple times (e.g. on window re-expose after a close).
90 void initWindowSwapChain(int index);
91 void releaseWindowSwapChain(int index);
92 // (Re)creates the offscreen render target using the current
93 // renderSize / renderFormat / samples in m_renderState. The
94 // offscreen RPD is also assigned to m_renderState->renderPassDescriptor.
95 void recreateOffscreenTarget();
96
97 Configuration m_conf;
98 std::vector<Gfx::OutputMapping> m_mappings;
99 std::vector<WindowOutput> m_windowOutputs;
100
101 std::shared_ptr<RenderState> m_renderState;
102 std::weak_ptr<RenderList> m_renderer;
103
104 TextureRenderTarget m_offscreenTarget;
105
106 Gfx::SwapchainFlag m_swapchainFlag{};
107 Gfx::SwapchainFormat m_swapchainFormat{};
108 std::function<void()> m_vsyncCallback;
109 // Stored resize callback from createOutput() so per-window events can
110 // request a full render-list rebuild (e.g. when a window becomes ready
111 // after the render list has already been built).
112 std::function<void()> m_onResize;
113};
114}
Base class for sink nodes (QWindow, spout, syphon, NDI output, ...)
Definition OutputNode.hpp:31
Definition OutputNode.hpp:18
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
GraphicsApi
Available graphics APIs to use.
Definition RenderState.hpp:22
Definition WindowSettings.hpp:49
Definition MultiWindowNode.hpp:35
Definition MultiWindowNode.hpp:41
Definition MultiWindowNode.hpp:11
Definition OutputNode.hpp:11
Definition OutputNode.hpp:61
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:122