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 <Qt3DRender/private/rendertarget_p.h>
41#include <Qt3DRender/qrendertarget.h>
42#include <Qt3DRender/private/qrendertarget_p.h>
43#include <Qt3DRender/qrendertargetoutput.h>
44#include <Qt3DRender/private/managers_p.h>
45#include <QVariant>
46
47QT_BEGIN_NAMESPACE
48
49using namespace Qt3DCore;
50
51namespace Qt3DRender {
52namespace Render {
53
54RenderTarget::RenderTarget()
55 : BackendNode()
56{
57}
58
59void RenderTarget::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
60{
61 const QRenderTarget *node = qobject_cast<const QRenderTarget *>(object: frontEnd);
62 if (!node)
63 return;
64
65 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
66
67 auto outputIds = qIdsForNodes(nodes: node->outputs());
68 std::sort(first: std::begin(cont&: outputIds), last: std::end(cont&: outputIds));
69
70 if (m_renderOutputs != outputIds) {
71 m_renderOutputs = outputIds;
72 markDirty(changes: AbstractRenderer::AllDirty);
73 }
74}
75
76void RenderTarget::cleanup()
77{
78 m_renderOutputs.clear();
79 QBackendNode::setEnabled(false);
80}
81
82void RenderTarget::appendRenderOutput(QNodeId outputId)
83{
84 if (!m_renderOutputs.contains(t: outputId))
85 m_renderOutputs.append(t: outputId);
86}
87
88void RenderTarget::removeRenderOutput(QNodeId outputId)
89{
90 m_renderOutputs.removeOne(t: outputId);
91}
92
93QVector<Qt3DCore::QNodeId> RenderTarget::renderOutputs() const
94{
95 return m_renderOutputs;
96}
97
98RenderTargetFunctor::RenderTargetFunctor(AbstractRenderer *renderer, RenderTargetManager *manager)
99 : m_renderer(renderer)
100 , m_renderTargetManager(manager)
101{
102}
103
104QBackendNode *RenderTargetFunctor::create(const QNodeCreatedChangeBasePtr &change) const
105{
106 RenderTarget *backend = m_renderTargetManager->getOrCreateResource(id: change->subjectId());
107 // Remove from the list of ids to destroy in case we were added to it
108 m_renderTargetManager->removeRenderTargetToCleanup(id: change->subjectId());
109 backend->setRenderer(m_renderer);
110 return backend;
111}
112
113QBackendNode *RenderTargetFunctor::get(QNodeId id) const
114{
115 return m_renderTargetManager->lookupResource(id);
116}
117
118void RenderTargetFunctor::destroy(QNodeId id) const
119{
120 // We add ourselves to the dirty list to tell the renderer that this rendertarget has been destroyed
121 m_renderTargetManager->addRenderTargetIdToCleanup(id);
122 m_renderTargetManager->releaseResource(id);
123}
124
125} // namespace Render
126} // namespace Qt3DRender
127
128QT_END_NAMESPACE
129

source code of qt3d/src/render/backend/rendertarget.cpp