1// Copyright (C) 2018 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 "updateentitylayersjob_p.h"
5#include <Qt3DRender/private/managers_p.h>
6#include <Qt3DRender/private/nodemanagers_p.h>
7#include <Qt3DRender/private/entity_p.h>
8#include <Qt3DRender/private/job_common_p.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DRender {
13
14namespace Render {
15
16UpdateEntityLayersJob::UpdateEntityLayersJob()
17 : m_manager(nullptr)
18{
19 SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateLayerEntity, 0)
20
21}
22
23void UpdateEntityLayersJob::run()
24{
25 Q_ASSERT(m_manager);
26 EntityManager *entityManager = m_manager->renderNodesManager();
27
28 const std::vector<HEntity> &handles = entityManager->activeHandles();
29
30 // Clear list of recursive layerIds
31 for (const HEntity &handle : handles) {
32 Entity *entity = entityManager->data(handle);
33 entity->clearRecursiveLayerIds();
34 }
35
36 LayerManager *layerManager = m_manager->layerManager();
37
38 // Set recursive layerIds on children
39 for (const HEntity &handle : handles) {
40 Entity *entity = entityManager->data(handle);
41 const Qt3DCore::QNodeIdVector entityLayers = entity->componentsUuid<Layer>();
42
43 for (const Qt3DCore::QNodeId &layerId : entityLayers) {
44 Layer *layer = layerManager->lookupResource(id: layerId);
45 if (layer->recursive()) {
46 // Find all children of the entity and add the layers to them
47 entity->traverse(operation: [layerId](Entity *e) {
48 e->addRecursiveLayerId(layerId);
49 });
50 }
51 }
52 }
53}
54
55} // Render
56
57} // Qt3DRender
58
59QT_END_NAMESPACE
60

source code of qt3d/src/render/jobs/updateentitylayersjob.cpp