Loading...
Searching...
No Matches
TextureShare.hpp
1#pragma once
2
3#include <score_plugin_gfx_export.h>
4
5#include <QSize>
6#include <QtGui/private/qrhi_p.h>
7
8#include <atomic>
9#include <memory>
10#include <mutex>
11
12namespace score::gfx
13{
14
18class SCORE_PLUGIN_GFX_EXPORT TextureShare
19{
20public:
23
24 TextureShare(const TextureShare&) = delete;
25 TextureShare& operator=(const TextureShare&) = delete;
26 TextureShare(TextureShare&&) = delete;
27 TextureShare& operator=(TextureShare&&) = delete;
28
45 bool setup(
46 QRhi* producer, QRhi* consumer, QSize size,
47 QRhiTexture::Format format = QRhiTexture::RGBA8);
48
62 bool setupProducer(
63 QRhi* producer, QSize size,
64 QRhiTexture::Format format = QRhiTexture::RGBA8);
65
77 bool setupConsumer(QRhi* consumer);
78
84 void resize(QSize newSize);
85
91 void cleanup();
92
93 bool isValid() const noexcept;
94
95 QSize size() const noexcept;
96
97 // === Producer Thread API ===
98
109 QRhiTextureRenderTarget* beginProducerFrame();
110
118 QRhiTexture* currentProducerTexture();
119
130 void endProducerFrame(QRhiCommandBuffer* cb);
131
135 QRhiRenderPassDescriptor* producerRenderPassDescriptor() const noexcept;
136
137 // === Consumer Thread API ===
138
149 QRhiTexture* acquireConsumerTexture(QRhiCommandBuffer* cb);
150
151 bool hasNewFrame() const noexcept;
152
153private:
154 struct Impl;
155 std::unique_ptr<Impl> m_impl;
156};
157
162{
163public:
164 virtual ~TextureShareBackend() = default;
165
166 // Single-thread setup (convenience, may violate QRhi threading rules)
167 virtual bool setup(
168 QRhi* producer, QRhi* consumer, QSize size, QRhiTexture::Format format)
169 = 0;
170
171 // Thread-safe split setup
172 virtual bool setupProducer(QRhi* producer, QSize size, QRhiTexture::Format format) = 0;
173 virtual bool setupConsumer(QRhi* consumer) = 0;
174
175 virtual void resize(QSize newSize) = 0;
176 virtual void cleanup() = 0;
177 virtual bool isValid() const noexcept = 0;
178 virtual bool isProducerReady() const noexcept = 0;
179
180 virtual QRhiTextureRenderTarget* beginProducerFrame() = 0;
181 virtual QRhiTexture* currentProducerTexture() = 0;
182 virtual void endProducerFrame(QRhiCommandBuffer* cb) = 0;
183 virtual QRhiRenderPassDescriptor* producerRenderPassDescriptor() const noexcept = 0;
184
185 virtual QRhiTexture* acquireConsumerTexture(QRhiCommandBuffer* cb) = 0;
186 virtual bool hasNewFrame() const noexcept = 0;
187 virtual QSize size() const noexcept = 0;
188};
189
190SCORE_PLUGIN_GFX_EXPORT
191std::unique_ptr<TextureShareBackend>
192createTextureShareBackend(QRhi* producer, QRhi* consumer);
193
194} // namespace score::gfx
Backend-specific implementation interface for GPU-only texture sharing.
Definition TextureShare.hpp:162
GPU-only triple-buffered texture sharing between two QRhi instances in different threads.
Definition TextureShare.hpp:19
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition TextureShare.cpp:1622