1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "renderpass_p.h"
6#include <Qt3DRender/private/filterkey_p.h>
7#include <Qt3DRender/qrenderstate.h>
8#include <Qt3DRender/qrenderpass.h>
9#include <Qt3DRender/qparameter.h>
10
11#include <Qt3DRender/private/qrenderpass_p.h>
12#include <Qt3DRender/private/renderstates_p.h>
13
14#include <algorithm>
15
16QT_BEGIN_NAMESPACE
17
18using namespace Qt3DCore;
19
20namespace Qt3DRender {
21namespace Render {
22
23RenderPass::RenderPass()
24 : BackendNode()
25{
26}
27
28RenderPass::~RenderPass()
29{
30}
31
32void RenderPass::cleanup()
33{
34 QBackendNode::setEnabled(false);
35 m_renderStates.clear();
36 m_filterKeyList.clear();
37 m_parameterPack.clear();
38 m_shaderUuid = Qt3DCore::QNodeId();
39}
40
41void RenderPass::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
42{
43 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
44 const QRenderPass *node = qobject_cast<const QRenderPass *>(object: frontEnd);
45 if (!node)
46 return;
47
48 if ((node->shaderProgram() && node->shaderProgram()->id() != m_shaderUuid) ||
49 (!node->shaderProgram() && !m_shaderUuid.isNull())) {
50 m_shaderUuid = node->shaderProgram() ? node->shaderProgram()->id() : QNodeId{};
51 }
52
53 auto filterList = qIdsForNodes(nodes: node->filterKeys());
54 std::sort(first: std::begin(cont&: filterList), last: std::end(cont&: filterList));
55 if (m_filterKeyList != filterList)
56 m_filterKeyList = filterList;
57
58 auto parameters = qIdsForNodes(nodes: node->parameters());
59 std::sort(first: std::begin(cont&: parameters), last: std::end(cont&: parameters));
60 if (m_parameterPack.parameters() != parameters)
61 m_parameterPack.setParameters(parameters);
62
63 auto renderStates = qIdsForNodes(nodes: node->renderStates());
64 std::sort(first: std::begin(cont&: renderStates), last: std::end(cont&: renderStates));
65 if (m_renderStates != renderStates)
66 m_renderStates = renderStates;
67
68 markDirty(changes: AbstractRenderer::AllDirty);
69}
70
71Qt3DCore::QNodeId RenderPass::shaderProgram() const
72{
73 return m_shaderUuid;
74}
75
76QList<Qt3DCore::QNodeId> RenderPass::filterKeys() const
77{
78 return m_filterKeyList;
79}
80
81QList<Qt3DCore::QNodeId> RenderPass::parameters() const
82{
83 return m_parameterPack.parameters();
84}
85
86QList<QNodeId> RenderPass::renderStates() const
87{
88 return m_renderStates;
89}
90
91void RenderPass::appendFilterKey(Qt3DCore::QNodeId filterKeyId)
92{
93 if (!m_filterKeyList.contains(t: filterKeyId))
94 m_filterKeyList.append(t: filterKeyId);
95}
96
97void RenderPass::removeFilterKey(Qt3DCore::QNodeId filterKeyId)
98{
99 m_filterKeyList.removeOne(t: filterKeyId);
100}
101
102void RenderPass::addRenderState(QNodeId renderStateId)
103{
104 if (!m_renderStates.contains(t: renderStateId))
105 m_renderStates.push_back(t: renderStateId);
106}
107
108void RenderPass::removeRenderState(QNodeId renderStateId)
109{
110 m_renderStates.removeOne(t: renderStateId);
111}
112
113
114} // namespace Render
115} // namespace Qt3DRender
116
117QT_END_NAMESPACE
118

source code of qt3d/src/render/materialsystem/renderpass.cpp