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 "material_p.h"
5#include "technique_p.h"
6#include "effect_p.h"
7#include "qparameter.h"
8#include "qtechnique.h"
9#include "qmaterial.h"
10#include "qeffect.h"
11#include <Qt3DRender/private/qmaterial_p.h>
12
13using namespace Qt3DCore;
14
15QT_BEGIN_NAMESPACE
16
17namespace Qt3DRender {
18namespace Render {
19
20Material::Material()
21 : BackendNode()
22{
23}
24
25Material::~Material()
26{
27 cleanup();
28}
29
30void Material::cleanup()
31{
32 QBackendNode::setEnabled(false);
33 m_parameterPack.clear();
34}
35
36void Material::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
37{
38 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
39 const QMaterial *node = qobject_cast<const QMaterial *>(object: frontEnd);
40 if (!node)
41 return;
42
43 AbstractRenderer::BackendNodeDirtySet dirty = firstTime ? AbstractRenderer::MaterialDirty : static_cast<AbstractRenderer::BackendNodeDirtyFlag>(0);
44
45 auto parameters = qIdsForNodes(nodes: node->parameters());
46 std::sort(first: std::begin(cont&: parameters), last: std::end(cont&: parameters));
47 if (m_parameterPack.parameters() != parameters) {
48 m_parameterPack.setParameters(parameters);
49 dirty |= AbstractRenderer::AllDirty;
50 }
51
52 const auto effectId = node->effect() ? node->effect()->id() : QNodeId{};
53 if (effectId != m_effectUuid) {
54 m_effectUuid = effectId;
55 dirty |= AbstractRenderer::AllDirty;
56 }
57
58 if (dirty)
59 markDirty(changes: dirty);
60}
61
62QList<Qt3DCore::QNodeId> Material::parameters() const
63{
64 return m_parameterPack.parameters();
65}
66
67Qt3DCore::QNodeId Material::effect() const
68{
69 return m_effectUuid;
70}
71
72} // namespace Render
73} // namespace Qt3DRender
74
75QT_END_NAMESPACE
76

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