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 "qrendertarget.h"
41#include "qrendertarget_p.h"
42#include "qrendertargetoutput.h"
43
44QT_BEGIN_NAMESPACE
45
46using namespace Qt3DCore;
47
48namespace Qt3DRender {
49
50/*!
51 \class Qt3DRender::QRenderTarget
52 \brief The QRenderTarget class encapsulates a target (usually a frame buffer
53 object) which the renderer can render into.
54 \since 5.7
55 \inmodule Qt3DRender
56
57 A Qt3DRender::QRenderTarget comprises of Qt3DRender::QRenderTargetOutput objects,
58 which specify the the buffers the render target is rendering to. The user can
59 specify MRT(Multiple Render Targets) by attaching multiple textures to different
60 attachment points. The results are undefined if the user tries to attach multiple
61 textures to the same attachment point. At render time, only the draw buffers specified
62 in the Qt3DRender::QRenderTargetSelector are used.
63
64 */
65/*!
66 \qmltype RenderTarget
67 \brief The RenderTarget class encapsulates a target (usually a frame buffer
68 object) which the renderer can render into.
69 \since 5.7
70 \inqmlmodule Qt3D.Render
71 \instantiates Qt3DRender::QRenderTarget
72
73 A RenderTarget comprises of RenderTargetOutput objects, which specify the the buffers
74 the render target is rendering to. The user can specify MRT(Multiple Render Targets)
75 by attaching multiple textures to different attachment points. The results are undefined
76 if the user tries to attach multiple textures to the same attachment point. At render
77 time, only the draw buffers specified in the RenderTargetSelector are used.
78 */
79
80/*!
81 \qmlproperty list<RenderTargetOutput> RenderTarget::attachments
82 Holds the attachments for the RenderTarget.
83*/
84
85/*! \internal */
86QRenderTargetPrivate::QRenderTargetPrivate()
87 : QComponentPrivate()
88{
89}
90
91/*!
92 The constructor creates a new QRenderTarget::QRenderTarget instance with
93 the specified \a parent.
94 */
95QRenderTarget::QRenderTarget(QNode *parent)
96 : QComponent(*new QRenderTargetPrivate, parent)
97{
98}
99
100/*! \internal */
101QRenderTarget::~QRenderTarget()
102{
103}
104
105/*! \internal */
106QRenderTarget::QRenderTarget(QRenderTargetPrivate &dd, QNode *parent)
107 : QComponent(dd, parent)
108{
109}
110
111/*!
112 Adds a chosen output via \a output.
113 */
114void QRenderTarget::addOutput(QRenderTargetOutput *output)
115{
116 Q_D(QRenderTarget);
117 if (output && !d->m_outputs.contains(t: output)) {
118 d->m_outputs.append(t: output);
119
120 // Ensures proper bookkeeping
121 d->registerDestructionHelper(node: output, func: &QRenderTarget::removeOutput, d->m_outputs);
122
123 if (!output->parent())
124 output->setParent(this);
125
126 d->updateNode(node: output, property: "output", change: Qt3DCore::PropertyValueAdded);
127 }
128}
129
130/*!
131 Removes a chosen output via \a output.
132 */
133void QRenderTarget::removeOutput(QRenderTargetOutput *output)
134{
135 Q_D(QRenderTarget);
136
137 if (!d->m_outputs.removeOne(t: output))
138 return;
139 d->updateNode(node: output, property: "output", change: Qt3DCore::PropertyValueRemoved);
140 // Remove bookkeeping connection
141 d->unregisterDestructionHelper(node: output);
142}
143
144/*!
145 \return the chosen outputs.
146 */
147QVector<QRenderTargetOutput *> QRenderTarget::outputs() const
148{
149 Q_D(const QRenderTarget);
150 return d->m_outputs;
151}
152
153Qt3DCore::QNodeCreatedChangeBasePtr QRenderTarget::createNodeCreationChange() const
154{
155 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QRenderTargetData>::create(arguments: this);
156 auto &data = creationChange->data;
157 data.outputIds = qIdsForNodes(nodes: outputs());
158 return creationChange;
159}
160
161} // namespace Qt3DRender
162
163QT_END_NAMESPACE
164

source code of qt3d/src/render/frontend/qrendertarget.cpp