Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
rhi_support.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6namespace QtMultimediaTest {
7
8using namespace Qt::Literals;
9
10#if QT_CONFIG(opengl)
12{
15 };
16
22 };
23 if (!rhi)
24 return q23::unexpected(u"QRhi::create failed"_s);
25
26 return OffscreenGlRhi{
28 std::move(rhi),
29 };
30}
31#endif
32
33#if QT_CONFIG(metal)
35{
38}
39#endif
40
41q23::expected<QByteArray, QString> readBackPlane(QRhi &rhi, quint64 handle, QSize planeSize,
42 QRhiTexture::Format format)
43{
44 std::unique_ptr<QRhiTexture> texture(
45 rhi.newTexture(format, planeSize, 1, QRhiTexture::UsedAsTransferSource));
46 if (!texture->createFrom(QRhiTexture::NativeTexture{ handle, 0 }))
47 return q23::unexpected(u"QRhiTexture::createFrom failed"_s);
48
49 QRhiResourceUpdateBatch *batch = rhi.nextResourceUpdateBatch();
50 QRhiReadbackResult result;
51 batch->readBackTexture(texture.get(), &result);
52
53 QRhiCommandBuffer *cb = nullptr;
54 if (rhi.beginOffscreenFrame(&cb) != QRhi::FrameOpSuccess || !cb)
55 return q23::unexpected(u"QRhi::beginOffscreenFrame failed"_s);
56 cb->resourceUpdate(batch);
57 rhi.endOffscreenFrame();
58
59 return result.data;
60}
61
62} // namespace QtMultimediaTest
q23::expected< QByteArray, QString > readBackPlane(QRhi &rhi, quint64 handle, QSize planeSize, QRhiTexture::Format format)