1// Copyright (C) 2016 Paul Lemire
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 "lightgatherer_p.h"
5#include <Qt3DRender/private/job_common_p.h>
6#include <Qt3DRender/private/managers_p.h>
7#include <Qt3DRender/private/entity_p.h>
8#include <Qt3DRender/private/qt3drender_global_p.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DRender {
13
14namespace Render {
15
16LightGatherer::LightGatherer()
17 : Qt3DCore::QAspectJob()
18 , m_manager(nullptr)
19 , m_environmentLight(nullptr)
20{
21 SET_JOB_RUN_STAT_TYPE(this, JobTypes::LightGathering, 0)
22}
23
24void LightGatherer::run()
25{
26 m_lights.clear();
27 m_environmentLight = nullptr;
28
29 const std::vector<HEntity> &handles = m_manager->activeHandles();
30 size_t envLightCount = 0;
31
32 for (const HEntity &handle : handles) {
33 Entity *node = m_manager->data(handle);
34 std::vector<Light *> lights = node->renderComponents<Light>();
35 if (!lights.empty())
36 m_lights.push_back(x: LightSource(node, std::move(lights)));
37 const std::vector<EnvironmentLight *> &envLights = node->renderComponents<EnvironmentLight>();
38 envLightCount += envLights.size();
39 if (!envLights.empty() && !m_environmentLight)
40 m_environmentLight = envLights.front();
41 }
42
43 if (envLightCount > 1)
44 qWarning() << "More than one environment light found, extra instances are ignored";
45}
46
47} // Render
48
49} // Qt3DRender
50
51QT_END_NAMESPACE
52

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