| 1 |
// Copyright (C) 2023 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#ifndef EXAMPLEWIDGET_H |
| 5 |
#define EXAMPLEWIDGET_H |
| 6 |
|
| 7 |
#include <QRhiWidget> |
| 8 |
#include <rhi/qrhi.h> |
| 9 |
|
| 10 |
class ExampleRhiWidget : public QRhiWidget |
| 11 |
{ |
| 12 |
Q_OBJECT |
| 13 |
|
| 14 |
public: |
| 15 |
ExampleRhiWidget(QWidget *parent = nullptr); |
| 16 |
|
| 17 |
void initialize(QRhiCommandBuffer *cb) override; |
| 18 |
void render(QRhiCommandBuffer *cb) override; |
| 19 |
void releaseResources() override; |
| 20 |
//![data-setters] |
| 21 |
void setCubeTextureText(const QString &s) |
| 22 |
{ |
| 23 |
if (itemData.cubeText == s) |
| 24 |
return; |
| 25 |
itemData.cubeText = s; |
| 26 |
itemData.cubeTextDirty = true; |
| 27 |
update(); |
| 28 |
} |
| 29 |
|
| 30 |
void setCubeRotation(float r) |
| 31 |
{ |
| 32 |
if (itemData.cubeRotation == r) |
| 33 |
return; |
| 34 |
itemData.cubeRotation = r; |
| 35 |
itemData.cubeRotationDirty = true; |
| 36 |
update(); |
| 37 |
} |
| 38 |
//![data-setters] |
| 39 |
|
| 40 |
signals: |
| 41 |
void resized(); |
| 42 |
void rhiChanged(const QString &apiName); |
| 43 |
|
| 44 |
private: |
| 45 |
QRhi *m_rhi = nullptr; |
| 46 |
int m_sampleCount = 1; |
| 47 |
QSize m_pixelSize; |
| 48 |
|
| 49 |
struct { |
| 50 |
QRhiResourceUpdateBatch *resourceUpdates = nullptr; |
| 51 |
std::unique_ptr<QRhiBuffer> vbuf; |
| 52 |
std::unique_ptr<QRhiBuffer> ubuf; |
| 53 |
std::unique_ptr<QRhiShaderResourceBindings> srb; |
| 54 |
std::unique_ptr<QRhiGraphicsPipeline> ps; |
| 55 |
std::unique_ptr<QRhiSampler> sampler; |
| 56 |
std::unique_ptr<QRhiTexture> cubeTex; |
| 57 |
QMatrix4x4 mvp; |
| 58 |
} scene; |
| 59 |
|
| 60 |
struct { |
| 61 |
QString cubeText; |
| 62 |
bool cubeTextDirty = false; |
| 63 |
float cubeRotation = 0.0f; |
| 64 |
bool cubeRotationDirty = false; |
| 65 |
} itemData; |
| 66 |
|
| 67 |
void initScene(); |
| 68 |
void updateMvp(); |
| 69 |
void updateCubeTexture(); |
| 70 |
}; |
| 71 |
|
| 72 |
#endif |