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 "qrendertarget.h"
5#include "qrendertarget_p.h"
6#include "qrendertargetoutput.h"
7
8QT_BEGIN_NAMESPACE
9
10using namespace Qt3DCore;
11
12namespace Qt3DRender {
13
14/*!
15 \class Qt3DRender::QRenderTarget
16 \brief The QRenderTarget class encapsulates a target (usually a frame buffer
17 object) which the renderer can render into.
18 \since 5.7
19 \inmodule Qt3DRender
20
21 A Qt3DRender::QRenderTarget comprises of Qt3DRender::QRenderTargetOutput objects,
22 which specify the the buffers the render target is rendering to. The user can
23 specify MRT(Multiple Render Targets) by attaching multiple textures to different
24 attachment points. The results are undefined if the user tries to attach multiple
25 textures to the same attachment point. At render time, only the draw buffers specified
26 in the Qt3DRender::QRenderTargetSelector are used.
27
28 */
29/*!
30 \qmltype RenderTarget
31 \brief The RenderTarget class encapsulates a target (usually a frame buffer
32 object) which the renderer can render into.
33 \since 5.7
34 \inqmlmodule Qt3D.Render
35 \instantiates Qt3DRender::QRenderTarget
36
37 A RenderTarget comprises of RenderTargetOutput objects, which specify the the buffers
38 the render target is rendering to. The user can specify MRT(Multiple Render Targets)
39 by attaching multiple textures to different attachment points. The results are undefined
40 if the user tries to attach multiple textures to the same attachment point. At render
41 time, only the draw buffers specified in the RenderTargetSelector are used.
42 */
43
44/*!
45 \qmlproperty list<RenderTargetOutput> RenderTarget::attachments
46 Holds the attachments for the RenderTarget.
47*/
48
49/*! \internal */
50QRenderTargetPrivate::QRenderTargetPrivate()
51 : QComponentPrivate()
52{
53}
54
55/*!
56 The constructor creates a new QRenderTarget::QRenderTarget instance with
57 the specified \a parent.
58 */
59QRenderTarget::QRenderTarget(QNode *parent)
60 : QComponent(*new QRenderTargetPrivate, parent)
61{
62}
63
64/*! \internal */
65QRenderTarget::~QRenderTarget()
66{
67}
68
69/*! \internal */
70QRenderTarget::QRenderTarget(QRenderTargetPrivate &dd, QNode *parent)
71 : QComponent(dd, parent)
72{
73}
74
75/*!
76 Adds a chosen output via \a output.
77 */
78void QRenderTarget::addOutput(QRenderTargetOutput *output)
79{
80 Q_D(QRenderTarget);
81 if (output && !d->m_outputs.contains(t: output)) {
82 d->m_outputs.append(t: output);
83
84 // Ensures proper bookkeeping
85 d->registerDestructionHelper(node: output, func: &QRenderTarget::removeOutput, d->m_outputs);
86
87 if (!output->parent())
88 output->setParent(this);
89
90 d->update();
91 }
92}
93
94/*!
95 Removes a chosen output via \a output.
96 */
97void QRenderTarget::removeOutput(QRenderTargetOutput *output)
98{
99 Q_D(QRenderTarget);
100
101 if (!d->m_outputs.removeOne(t: output))
102 return;
103 d->update();
104 // Remove bookkeeping connection
105 d->unregisterDestructionHelper(node: output);
106}
107
108/*!
109 \return the chosen outputs.
110 */
111QList<QRenderTargetOutput *> QRenderTarget::outputs() const
112{
113 Q_D(const QRenderTarget);
114 return d->m_outputs;
115}
116
117} // namespace Qt3DRender
118
119QT_END_NAMESPACE
120
121#include "moc_qrendertarget.cpp"
122

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