Loading...
Searching...
No Matches
RhiPreviewWidget.hpp
1#pragma once
2#include <ossia/gfx/port_index.hpp>
3
4#include <QPointer>
5#include <QWidget>
6
7#include <score_plugin_gfx_export.h>
8
9#include <cstdint>
10#include <functional>
11#include <memory>
12
13struct QRhiReadbackResult;
14
15namespace score::gfx
16{
17struct Graph;
18struct BackgroundNode;
19}
20
21namespace Gfx
22{
23class GfxContext;
24using port_index = ossia::gfx::port_index;
25
45class SCORE_PLUGIN_GFX_EXPORT RhiPreviewWidget : public QWidget
46{
47public:
48 explicit RhiPreviewWidget(QWidget* parent = nullptr);
49 ~RhiPreviewWidget() override;
50
55 void useGraph(
56 score::gfx::Graph* graph,
57 std::function<void(score::gfx::BackgroundNode&)> onAttached,
58 std::function<void(score::gfx::BackgroundNode&)> onAboutToDetach);
59
64 void useContext(GfxContext* ctx, port_index producer);
65 void setProducer(port_index producer);
66
69 score::gfx::BackgroundNode* liveNode() const noexcept;
70
75 void detach();
76
77protected:
78 void paintEvent(QPaintEvent* ev) override;
79 void resizeEvent(QResizeEvent* ev) override;
80 void timerEvent(QTimerEvent* ev) override;
81
82private:
83 void attach();
84
85 enum class Backend
86 {
87 None,
88 Graph,
89 Context
90 } m_backend{Backend::None};
91
92 // Graph backend
93 score::gfx::Graph* m_graph{};
94 std::function<void(score::gfx::BackgroundNode&)> m_onAttached;
95 std::function<void(score::gfx::BackgroundNode&)> m_onAboutToDetach;
96
97 // Context backend
98 // QPointer, not a raw pointer: an inspector widget can be destroyed after
99 // the GfxContext (a queued DeferredDelete outliving ~DocumentPlugin), and
100 // detach() then calls into it. QPointer makes the existing null check hold.
101 QPointer<GfxContext> m_ctx;
102 port_index m_producer{-1, -1};
103 int32_t m_screenNodeId{-1};
104 bool m_edgeConnected{false};
105
106 std::shared_ptr<QRhiReadbackResult> m_readback;
107 score::gfx::BackgroundNode* m_node{}; // owned by m_graph or m_ctx after attach
108
119 score::gfx::BackgroundNode* liveNodeImpl() const noexcept
120 {
121 if(!m_node)
122 return nullptr;
123 if(m_backend == Backend::Context && !m_ctx)
124 return nullptr; // owner already gone; m_node is dangling
125 return m_node;
126 }
127 int m_timerId{};
128};
129}
Definition GfxContext.hpp:69
A QWidget that paints a score::gfx render-graph output without using QWidget::createWindowContainer (...
Definition RhiPreviewWidget.hpp:46
Binds the rendering pipeline to ossia processes.
Definition AssetTable.cpp:7
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition BackgroundNode.hpp:16
Represents a graph of renderers.
Definition score-plugin-gfx/Gfx/Graph/Graph.hpp:25