Debian Codegraph @

tests/manual/rhi/rhiwidgetproto/examplewidget.h

raw
1 // Copyright (C) 2021 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #ifndef EXAMPLEWIDGET_H
5 #define EXAMPLEWIDGET_H
6
7 #include "rhiwidget.h"
8 #include <rhi/qrhi.h>
9
10 class ExampleRhiWidget : public QRhiWidget
11 {
12 public:
13 ExampleRhiWidget(QWidget *parent = nullptr, Qt::WindowFlags f = {});
14
15 void initialize(QRhi *rhi, QRhiTexture *outputTexture) override;
16 void render(QRhiCommandBuffer *cb) override;
17
18 void setCubeTextureText(const QString &s)
19 {
20 if (itemData.cubeText == s)
21 return;
22 itemData.cubeText = s;
23 itemData.cubeTextDirty = true;
24 update();
25 }
26
27 void setCubeRotation(float r)
28 {
29 if (itemData.cubeRotation == r)
30 return;
31 itemData.cubeRotation = r;
32 itemData.cubeRotationDirty = true;
33 update();
34 }
35
36 private:
37 QRhi *m_rhi = nullptr;
38 QRhiTexture *m_output = nullptr;
39 QScopedPointer<QRhiRenderBuffer> m_ds;
40 QScopedPointer<QRhiTextureRenderTarget> m_rt;
41 QScopedPointer<QRhiRenderPassDescriptor> m_rp;
42
43 struct {
44 QRhiResourceUpdateBatch *resourceUpdates = nullptr;
45 QScopedPointer<QRhiBuffer> vbuf;
46 QScopedPointer<QRhiBuffer> ubuf;
47 QScopedPointer<QRhiShaderResourceBindings> srb;
48 QScopedPointer<QRhiGraphicsPipeline> ps;
49 QScopedPointer<QRhiSampler> sampler;
50 QScopedPointer<QRhiTexture> cubeTex;
51 QMatrix4x4 mvp;
52 } scene;
53
54 void initScene();
55 void updateMvp();
56 void updateCubeTexture();
57
58 struct {
59 QString cubeText;
60 bool cubeTextDirty = false;
61 float cubeRotation = 0.0f;
62 bool cubeRotationDirty = false;
63 } itemData;
64 };
65
66 #endif