1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qtechniquefilter.h"
5#include "qtechniquefilter_p.h"
6#include <Qt3DRender/qfilterkey.h>
7#include <Qt3DRender/qparameter.h>
8
9QT_BEGIN_NAMESPACE
10
11
12namespace Qt3DRender {
13
14using namespace Qt3DCore;
15
16QTechniqueFilterPrivate::QTechniqueFilterPrivate()
17 : QFrameGraphNodePrivate()
18{
19}
20
21/*!
22 \class Qt3DRender::QTechniqueFilter
23 \inmodule Qt3DRender
24 \since 5.7
25 \brief A QFrameGraphNode used to select QTechniques to use.
26
27 A Qt3DRender::QTechniqueFilter specifies which techniques are used
28 by the FrameGraph when rendering the entities. QTechniqueFilter specifies
29 a list of Qt3DRender::QFilterKey objects and Qt3DRender::QParameter objects.
30 When QTechniqueFilter is present in the FrameGraph, only the techiques matching
31 the keys in the list are used for rendering. The parameters in the list can be used
32 to set values for shader parameters. The parameters in QTechniqueFilter
33 override parameters in QMaterial, QEffect, QTechnique and QRenderPass, but are overridden
34 by parameters in QRenderPassFilter.
35*/
36
37/*!
38 \qmltype TechniqueFilter
39 \inqmlmodule Qt3D.Render
40 \nativetype Qt3DRender::QTechniqueFilter
41 \inherits FrameGraphNode
42 \since 5.7
43 \brief A FrameGraphNode used to select used Techniques.
44
45 A TechniqueFilter specifies which techniques are used by the FrameGraph
46 when rendering the entities. TechniqueFilter specifies
47 a list of FilterKey objects and Parameter objects.
48 When TechniqueFilter is present in the FrameGraph, only the techiques matching
49 the keys in list are used for rendering. The parameters in the list can be used
50 to set values for shader parameters. The parameters in TechniqueFilter
51 override parameters in Material, Effect, Technique and RenderPass, but are overridden
52 by parameters in RenderPassFilter.
53*/
54
55/*!
56 \qmlproperty list<FilterKey> TechniqueFilter::matchAll
57 Holds the list of filterkeys used by the TechiqueFilter
58*/
59
60/*!
61 \qmlproperty list<Parameter> TechniqueFilter::parameters
62 Holds the list of parameters used by the TechiqueFilter
63*/
64
65/*!
66 The constructor creates an instance with the specified \a parent.
67 */
68QTechniqueFilter::QTechniqueFilter(QNode *parent)
69 : QFrameGraphNode(*new QTechniqueFilterPrivate, parent)
70{
71}
72
73/*! \internal */
74QTechniqueFilter::~QTechniqueFilter()
75{
76}
77
78/*! \internal */
79QTechniqueFilter::QTechniqueFilter(QTechniqueFilterPrivate &dd, QNode *parent)
80 : QFrameGraphNode(dd, parent)
81{
82}
83
84/*!
85 Returns a vector of the current keys for the filter.
86 */
87QList<QFilterKey *> QTechniqueFilter::matchAll() const
88{
89 Q_D(const QTechniqueFilter);
90 return d->m_matchList;
91}
92
93/*!
94 Add the \a filterKey to the match vector.
95 */
96void QTechniqueFilter::addMatch(QFilterKey *filterKey)
97{
98 Q_ASSERT(filterKey);
99 Q_D(QTechniqueFilter);
100 if (!d->m_matchList.contains(t: filterKey)) {
101 d->m_matchList.append(t: filterKey);
102
103 // Ensures proper bookkeeping
104 d->registerDestructionHelper(node: filterKey, func: &QTechniqueFilter::removeMatch, d->m_matchList);
105
106 // We need to add it as a child of the current node if it has been declared inline
107 // Or not previously added as a child of the current node so that
108 // 1) The backend gets notified about it's creation
109 // 2) When the current node is destroyed, it gets destroyed as well
110 if (!filterKey->parent())
111 filterKey->setParent(this);
112
113 d->update();
114 }
115}
116
117/*!
118 Remove the \a filterKey from the match vector.
119 */
120void QTechniqueFilter::removeMatch(QFilterKey *filterKey)
121{
122 Q_ASSERT(filterKey);
123 Q_D(QTechniqueFilter);
124 if (!d->m_matchList.removeOne(t: filterKey))
125 return;
126 d->update();
127 // Remove bookkeeping connection
128 d->unregisterDestructionHelper(node: filterKey);
129}
130
131/*!
132 Add \a parameter to the vector of parameters that will be passed to the graphics pipeline.
133 */
134void QTechniqueFilter::addParameter(QParameter *parameter)
135{
136 Q_ASSERT(parameter);
137 Q_D(QTechniqueFilter);
138 if (!d->m_parameters.contains(t: parameter)) {
139 d->m_parameters.append(t: parameter);
140
141 // Ensures proper bookkeeping
142 d->registerDestructionHelper(node: parameter, func: &QTechniqueFilter::removeParameter, d->m_parameters);
143
144 // We need to add it as a child of the current node if it has been declared inline
145 // Or not previously added as a child of the current node so that
146 // 1) The backend gets notified about it's creation
147 // 2) When the current node is destroyed, the child parameters get destroyed as well
148 if (!parameter->parent())
149 parameter->setParent(this);
150
151 d->update();
152 }
153}
154
155/*!
156 Remove \a parameter from the vector of parameters passed to the graphics pipeline.
157 */
158void QTechniqueFilter::removeParameter(QParameter *parameter)
159{
160 Q_ASSERT(parameter);
161 Q_D(QTechniqueFilter);
162 if (!d->m_parameters.removeOne(t: parameter))
163 return;
164 d->update();
165 // Remove bookkeeping connection
166 d->unregisterDestructionHelper(node: parameter);
167}
168
169/*!
170 Returns the current vector of parameters.
171 */
172QList<QParameter *> QTechniqueFilter::parameters() const
173{
174 Q_D(const QTechniqueFilter);
175 return d->m_parameters;
176}
177
178} // namespace Qt3DRender
179
180QT_END_NAMESPACE
181
182#include "moc_qtechniquefilter.cpp"
183

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qt3d/src/render/framegraph/qtechniquefilter.cpp