1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
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 "light_p.h" |
5 | #include "qabstractlight.h" |
6 | #include "qabstractlight_p.h" |
7 | #include <private/abstractrenderer_p.h> |
8 | #include <private/nodemanagers_p.h> |
9 | #include <private/qbackendnode_p.h> |
10 | #include <private/managers_p.h> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | using namespace Qt3DCore; |
15 | |
16 | namespace Qt3DRender { |
17 | namespace Render { |
18 | |
19 | QNodeId Light::shaderData() const |
20 | { |
21 | return m_shaderDataId; |
22 | } |
23 | |
24 | void Light::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) |
25 | { |
26 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
27 | const QAbstractLight *node = qobject_cast<const QAbstractLight *>(object: frontEnd); |
28 | if (!node) |
29 | return; |
30 | |
31 | if (firstTime) { |
32 | QAbstractLightPrivate *d = static_cast<QAbstractLightPrivate *>(QAbstractLightPrivate::get(q: const_cast<Qt3DCore::QNode *>(frontEnd))); |
33 | m_shaderDataId = d->m_shaderData ? d->m_shaderData->id() : QNodeId{}; |
34 | BackendNode::markDirty(changes: AbstractRenderer::LightsDirty); |
35 | } |
36 | } |
37 | |
38 | RenderLightFunctor::RenderLightFunctor(AbstractRenderer *renderer, NodeManagers *managers) |
39 | : m_managers(managers) |
40 | , m_renderer(renderer) |
41 | { |
42 | } |
43 | |
44 | Qt3DCore::QBackendNode *RenderLightFunctor::create(Qt3DCore::QNodeId id) const |
45 | { |
46 | Light *backend = m_managers->lightManager()->getOrCreateResource(id); |
47 | backend->setRenderer(m_renderer); |
48 | return backend; |
49 | } |
50 | |
51 | Qt3DCore::QBackendNode *RenderLightFunctor::get(Qt3DCore::QNodeId id) const |
52 | { |
53 | return m_managers->lightManager()->lookupResource(id); |
54 | } |
55 | |
56 | void RenderLightFunctor::destroy(Qt3DCore::QNodeId id) const |
57 | { |
58 | Light *backend = m_managers->lightManager()->getOrCreateResource(id); |
59 | m_renderer->markDirty(changes: AbstractRenderer::LightsDirty, node: backend); |
60 | m_managers->lightManager()->releaseResource(id); |
61 | } |
62 | |
63 | } // namespace Render |
64 | } // namespace Qt3DRender |
65 | |
66 | QT_END_NAMESPACE |
67 |