Loading...
Searching...
No Matches
RenderState.hpp
1#pragma once
2#include <QOffscreenSurface>
3#include <QtGui/private/qrhi_p.h>
4
5#include <score_plugin_gfx_export.h>
6
7#include <functional>
8
9#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
10using QRhiBufferReadbackResult = QRhiReadbackResult;
11#endif
12
13class QOffscreenSurface;
14class QWindow;
15namespace score::gfx
16{
17class RenderList;
22{
23 Null,
24 OpenGL,
25 Vulkan,
26 D3D11,
27 Metal,
28 D3D12
29};
30
31class Window;
32
37{
38 RenderState() = default;
39 RenderState(const RenderState&) = delete;
40 RenderState(RenderState&&) = delete;
41 RenderState& operator=(const RenderState&) = delete;
42 RenderState& operator=(RenderState&&) = delete;
43
44 QRhi* rhi{};
45 QRhiRenderPassDescriptor* renderPassDescriptor{};
46 std::weak_ptr<RenderList> renderer{};
47
48 QOffscreenSurface* surface{};
49 std::weak_ptr<score::gfx::Window>
50 window{}; // Not always set, only used to get mouse events & such.
51 QSize renderSize{};
52 QSize outputSize{};
53 int samples{1};
54 QRhiTexture::Format renderFormat{QRhiTexture::RGBA8};
55 GraphicsApi api{};
56 QShaderVersion version{};
57
58 // Called after QRhi is destroyed to clean up an imported VkDevice
59 std::function<void()> customDeviceCleanup;
60
61 void destroy()
62 {
63 window.reset();
64
65 delete rhi;
66 rhi = nullptr;
67
68 // Destroy imported VkDevice AFTER QRhi (which still references it during shutdown)
69 if(customDeviceCleanup)
70 {
71 customDeviceCleanup();
72 customDeviceCleanup = nullptr;
73 }
74
75 delete surface;
76 surface = nullptr;
77 }
78};
79
80SCORE_PLUGIN_GFX_EXPORT
81std::shared_ptr<RenderState>
82createRenderState(GraphicsApi graphicsApi, QSize sz, QWindow* window);
83
84static const constexpr int32_t invalid_node_index = -1;
85}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
GraphicsApi
Available graphics APIs to use.
Definition RenderState.hpp:22
Global state associated to a rendering context.
Definition RenderState.hpp:37