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