QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCOffscreenRenderer.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtCore/QSize>
5#include <QtCore/QUrl>
6#include <QtGui/QImage>
7#include <memory>
8
9class QQmlEngine;
10class QQmlComponent;
11class QQuickItem;
12class QQuickWindow;
13class QQuickRenderControl;
14class QRhi;
15class QRhiTexture;
16class QRhiRenderBuffer;
17class QRhiTextureRenderTarget;
18class QRhiRenderPassDescriptor;
19
21class QGCOffscreenRenderer : public QObject
22{
23 Q_OBJECT
24
25public:
26 explicit QGCOffscreenRenderer(QObject* parent = nullptr);
27 ~QGCOffscreenRenderer() override;
28
29 bool load(const QUrl& qmlSource, const QSize& pixelSize);
30
31 QImage renderToImage();
32
33 bool isValid() const { return _initialized; }
34
35private:
36 void releaseRhiResources();
37 bool ensureRhiTarget();
38
39 std::unique_ptr<QQuickRenderControl> _renderControl;
40 std::unique_ptr<QQuickWindow> _quickWindow;
41 std::unique_ptr<QQmlEngine> _qmlEngine;
42 std::unique_ptr<QQmlComponent> _qmlComponent;
43 QQuickItem* _rootItem = nullptr;
44
45 QRhi* _rhi = nullptr;
46 std::unique_ptr<QRhiTexture> _texture;
47 std::unique_ptr<QRhiRenderBuffer> _depthStencil;
48 std::unique_ptr<QRhiTextureRenderTarget> _renderTarget;
49 std::unique_ptr<QRhiRenderPassDescriptor> _rpDesc;
50
51 QSize _pixelSize;
52 bool _initialized = false;
53};
Renders a QML scene into an offscreen RHI texture and reads it back to a QImage.
bool load(const QUrl &qmlSource, const QSize &pixelSize)