aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickrhiitem/testrhiitem.h
blob: 6778f96d7be3a513a98017cd2ee9f3b2804b571f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef TESTRHIITEM_H
#define TESTRHIITEM_H

#include <QQuickRhiItem>
#include <rhi/qrhi.h>

class TestRenderer : public QQuickRhiItemRenderer
{
protected:
    void initialize(QRhiCommandBuffer *cb) override;
    void synchronize(QQuickRhiItem *item) override;
    void render(QRhiCommandBuffer *cb) override;

private:
    QRhi *m_rhi = nullptr;
    int m_sampleCount = 1;

    struct {
        QRhiResourceUpdateBatch *resourceUpdates = nullptr;
        std::unique_ptr<QRhiBuffer> vbuf;
        std::unique_ptr<QRhiBuffer> ubuf;
        std::unique_ptr<QRhiShaderResourceBindings> srb;
        std::unique_ptr<QRhiGraphicsPipeline> ps;
        std::unique_ptr<QRhiSampler> sampler;
        std::unique_ptr<QRhiTexture> tex;
        QMatrix4x4 mvp;
    } scene;

    struct {
        QColor color;
    } itemData;

    void initScene();
    void updateTexture();

    friend class tst_QQuickRhiItem;
};

class TestRhiItem : public QQuickRhiItem
{
    Q_OBJECT
    QML_NAMED_ELEMENT(TestRhiItem)
    Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)

public:
    QQuickRhiItemRenderer *createRenderer() override { return new TestRenderer; }

    QColor color() const { return m_color; }
    void setColor(QColor c);

signals:
    void colorChanged();

private:
    QColor m_color;
};

#endif