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 <Qt3DRender/private/rendertarget_p.h>
5#include <Qt3DRender/qrendertarget.h>
6#include <Qt3DRender/private/qrendertarget_p.h>
7#include <Qt3DRender/qrendertargetoutput.h>
8#include <Qt3DRender/private/managers_p.h>
9#include <QVariant>
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt3DCore;
14
15namespace Qt3DRender {
16namespace Render {
17
18RenderTarget::RenderTarget()
19 : BackendNode()
20 , m_dirty(false)
21{
22}
23
24void RenderTarget::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
25{
26 const QRenderTarget *node = qobject_cast<const QRenderTarget *>(object: frontEnd);
27 if (!node)
28 return;
29
30 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
31
32 auto outputIds = qIdsForNodes(nodes: node->outputs());
33 std::sort(first: std::begin(cont&: outputIds), last: std::end(cont&: outputIds));
34
35 if (m_renderOutputs != outputIds) {
36 m_renderOutputs = outputIds;
37 m_dirty = true;
38 markDirty(changes: AbstractRenderer::AllDirty);
39 }
40}
41
42void RenderTarget::cleanup()
43{
44 m_renderOutputs.clear();
45 m_dirty = false;
46 QBackendNode::setEnabled(false);
47}
48
49QList<Qt3DCore::QNodeId> RenderTarget::renderOutputs() const
50{
51 return m_renderOutputs;
52}
53
54bool RenderTarget::isDirty() const
55{
56 return m_dirty;
57}
58
59void RenderTarget::unsetDirty()
60{
61 m_dirty = false;
62}
63
64RenderTargetFunctor::RenderTargetFunctor(AbstractRenderer *renderer, RenderTargetManager *manager)
65 : m_renderer(renderer)
66 , m_renderTargetManager(manager)
67{
68}
69
70QBackendNode *RenderTargetFunctor::create(QNodeId id) const
71{
72 RenderTarget *backend = m_renderTargetManager->getOrCreateResource(id);
73 // Remove from the list of ids to destroy in case we were added to it
74 m_renderTargetManager->removeRenderTargetToCleanup(id);
75 backend->setRenderer(m_renderer);
76 return backend;
77}
78
79QBackendNode *RenderTargetFunctor::get(QNodeId id) const
80{
81 return m_renderTargetManager->lookupResource(id);
82}
83
84void RenderTargetFunctor::destroy(QNodeId id) const
85{
86 // We add ourselves to the dirty list to tell the renderer that this rendertarget has been destroyed
87 m_renderTargetManager->addRenderTargetIdToCleanup(id);
88 m_renderTargetManager->releaseResource(id);
89}
90
91} // namespace Render
92} // namespace Qt3DRender
93
94QT_END_NAMESPACE
95

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