summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3drender/items/quick3dtechnique.cpp
blob: 5d871893f5afd9371346d32328b5a674783b4580 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include <Qt3DQuickRender/private/quick3dtechnique_p.h>

QT_BEGIN_NAMESPACE

namespace Qt3DRender {
namespace Render {
namespace Quick {

Quick3DTechnique::Quick3DTechnique(QObject *parent)
    : QObject(parent)
{
}

QQmlListProperty<QRenderPass> Quick3DTechnique::renderPassList()
{
    using qt_size_type = qsizetype;
    using ListContentType = QRenderPass;
    auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *renderPass) {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique)
            technique->parentTechnique()->addRenderPass(renderPass);
    };
    auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique)
            return technique->parentTechnique()->renderPasses().size();
        return 0;
    };
    auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique)
            return qobject_cast<QRenderPass *>(technique->parentTechnique()->renderPasses().at(index));
        return nullptr;
    };
    auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique) {
            const auto passes = technique->parentTechnique()->renderPasses();
            for (QRenderPass *pass : passes)
                technique->parentTechnique()->removeRenderPass(pass);
        }
    };

    return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
}

QQmlListProperty<QParameter> Quick3DTechnique::parameterList()
{
    using qt_size_type = qsizetype;
    using ListContentType = QParameter;
    auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        technique->parentTechnique()->addParameter(param);
    };
    auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        return technique->parentTechnique()->parameters().size();
    };
    auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        return technique->parentTechnique()->parameters().at(index);
    };
    auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        const auto parameters = technique->parentTechnique()->parameters();
        for (QParameter *p : parameters)
            technique->parentTechnique()->removeParameter(p);
    };

    return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
}

QQmlListProperty<QFilterKey> Quick3DTechnique::filterKeyList()
{
    using qt_size_type = qsizetype;
    using ListContentType = QFilterKey;
    auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *filterKey) {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique) {
            if (!filterKey->parent())
                filterKey->setParent(technique->parentTechnique());
            technique->parentTechnique()->addFilterKey(filterKey);
        }
    };
    auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique)
            return technique->parentTechnique()->filterKeys().size();
        return 0;
    };
    auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique)
            return technique->parentTechnique()->filterKeys().at(index);
        return nullptr;
    };
    auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
        Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object);
        if (technique) {
            const auto keys = technique->parentTechnique()->filterKeys();
            for (QFilterKey *a : keys)
                technique->parentTechnique()->removeFilterKey(a);
        }
    };

    return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
}

} // namespace Quick
} // namespace Render
} // namespace Qt3DRender

QT_END_NAMESPACE

#include "moc_quick3dtechnique_p.cpp"