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
67protected:
68 void paintEvent(QPaintEvent* ev) override;
69 void resizeEvent(QResizeEvent* ev) override;
70 void timerEvent(QTimerEvent* ev) override;
71
72private:
73 void attach();
74 void detach();
75
76 enum class Backend
77 {
78 None,
79 Graph,
80 Context
81 } m_backend{Backend::None};
82
83 // Graph backend
84 score::gfx::Graph* m_graph{};
85 std::function<void(score::gfx::BackgroundNode&)> m_onAttached;
86 std::function<void(score::gfx::BackgroundNode&)> m_onAboutToDetach;
87
88 // Context backend
89 // QPointer, not a raw pointer: an inspector widget can be destroyed after
90 // the GfxContext (a queued DeferredDelete outliving ~DocumentPlugin), and
91 // detach() then calls into it. QPointer makes the existing null check hold.
92 QPointer<GfxContext> m_ctx;
93 port_index m_producer{-1, -1};
94 int32_t m_screenNodeId{-1};
95 bool m_edgeConnected{false};
96
97 std::shared_ptr<QRhiReadbackResult> m_readback;
98 score::gfx::BackgroundNode* m_node{}; // owned by m_graph or m_ctx after attach
99
110 score::gfx::BackgroundNode* liveNode() const noexcept
111 {
112 if(!m_node)
113 return nullptr;
114 if(m_backend == Backend::Context && !m_ctx)
115 return nullptr; // owner already gone; m_node is dangling
116 return m_node;
117 }
118 int m_timerId{};
119};
120}
Definition GfxContext.hpp:68
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:22