1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qrendertargetselector.h"
41#include "qrendertargetselector_p.h"
42#include <Qt3DRender/qrendertarget.h>
43#include <Qt3DRender/private/qrenderpass_p.h>
44#include <Qt3DRender/qframegraphnodecreatedchange.h>
45
46QT_BEGIN_NAMESPACE
47
48using namespace Qt3DCore;
49
50namespace Qt3DRender {
51/*!
52 \class Qt3DRender::QRenderTargetSelector
53 \inmodule Qt3DRender
54 \since 5.7
55 \brief Provides a way of specifying a render target.
56
57 A Qt3DRender::QRenderTargetSelector is used to select active Qt3DRender::QRenderTarget
58 for the FrameGraph. When QRenderTargetSelector is present in the FrameGraph,
59 the rendering is directed into QTexture objects or draw buffers instead of the surface
60 specified in the Qt3DRender::QRenderSurfaceSelector. A render buffer is automatically
61 generated for an attachment point if drawBuffers contain attachment point that any
62 output in the QRenderTarget do not specify. If the drawBuffers is empty,
63 the renderer will default to using all the outputs in QRenderTarget.
64 */
65
66/*!
67 \qmltype RenderTargetSelector
68 \inqmlmodule Qt3D.Render
69 \since 5.7
70 \instantiates Qt3DRender::QRenderTargetSelector
71 \inherits FrameGraphNode
72 \brief Provides a way of specifying a render target.
73
74 A RenderTargetSelector is used to select active RenderTarget
75 for the FrameGraph. When RenderTargetSelector is present in the FrameGraph,
76 the rendering is directed into Texture objects or draw buffers instead of the surface
77 specified in the RenderSurfaceSelector.
78 */
79/*!
80 \qmlproperty list<variant> RenderTargetSelector::drawBuffers
81 Holds the list of draw buffers enabled for the RenderTarget.
82
83 \sa Qt3DRender::QRenderTargetOutput::AttachmentPoint
84 */
85
86QRenderTargetSelectorPrivate::QRenderTargetSelectorPrivate()
87 : QFrameGraphNodePrivate()
88 , m_target(nullptr)
89{
90}
91
92/*!
93 Constructs QRenderTargetSelector with given \a parent.
94 */
95QRenderTargetSelector::QRenderTargetSelector(QNode *parent)
96 : QFrameGraphNode(*new QRenderTargetSelectorPrivate, parent)
97{
98}
99
100/*! \internal */
101QRenderTargetSelector::~QRenderTargetSelector()
102{
103}
104
105/*!
106 \property QRenderTargetSelector::target
107 Holds the current render target
108 */
109
110/*! \qmlproperty RenderTarget Qt3D.Render::RenderTargetSelector::target
111
112 Holds the current render target
113 */
114void QRenderTargetSelector::setTarget(QRenderTarget *target)
115{
116 Q_D(QRenderTargetSelector);
117 if (d->m_target != target) {
118
119 if (d->m_target)
120 d->unregisterDestructionHelper(node: d->m_target);
121
122 // For inline declaration cases
123 if (target != nullptr && !target->parent())
124 target->setParent(this);
125
126 d->m_target = target;
127
128 if (d->m_target)
129 d->registerDestructionHelper(node: d->m_target, func: &QRenderTargetSelector::setTarget, d->m_target);
130
131 emit targetChanged(target);
132 }
133}
134
135QRenderTarget *QRenderTargetSelector::target() const
136{
137 Q_D(const QRenderTargetSelector);
138 return d->m_target;
139}
140
141/*!
142 Sets the draw \a buffers to be used. The draw buffers should be
143 matching the Qt3DRender::QRenderTargetOutput::AttachmentPoint
144 defined in the attachments of the Qt3DRender::QRenderTarget associated to the
145 Qt3DRender::QRenderTargetSelector instance.
146
147 \note At render time, if no draw buffer has been specified, the renderer will
148 default to using all the attachments' draw buffers.
149 */
150void QRenderTargetSelector::setOutputs(const QVector<QRenderTargetOutput::AttachmentPoint> &buffers)
151{
152 Q_D(QRenderTargetSelector);
153 if (buffers != d->m_outputs) {
154 d->m_outputs = buffers;
155 d->update();
156 }
157}
158
159/*!
160 \return the list of draw buffers for the current Qt3DRender::QRenderTargetSelector instance.
161 */
162QVector<QRenderTargetOutput::AttachmentPoint> QRenderTargetSelector::outputs() const
163{
164 Q_D(const QRenderTargetSelector);
165 return d->m_outputs;
166}
167
168/*! \internal */
169QRenderTargetSelector::QRenderTargetSelector(QRenderTargetSelectorPrivate &dd, QNode *parent)
170 : QFrameGraphNode(dd, parent)
171{
172}
173
174Qt3DCore::QNodeCreatedChangeBasePtr QRenderTargetSelector::createNodeCreationChange() const
175{
176 auto creationChange = QFrameGraphNodeCreatedChangePtr<QRenderTargetSelectorData>::create(arguments: this);
177 auto &data = creationChange->data;
178 Q_D(const QRenderTargetSelector);
179 data.targetId = qIdForNode(node: d->m_target);
180 data.outputs = d->m_outputs;
181 return creationChange;
182}
183
184} // namespace Qt3DRender
185
186QT_END_NAMESPACE
187

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