summaryrefslogtreecommitdiffstats
path: root/src/render/backend/entity.cpp
blob: 04cb606c5fee2b4ab3f466f9b68a016d05f2a96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/****************************************************************************
**
** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "entity_p.h"
#include <Qt3DRender/private/managers_p.h>
#include <Qt3DRender/private/nodemanagers_p.h>
#include <Qt3DRender/qlight.h>
#include <Qt3DRender/qlayer.h>
#include <Qt3DRender/qmaterial.h>
#include <Qt3DRender/qmesh.h>
#include <Qt3DRender/private/renderlogging_p.h>
#include <Qt3DRender/private/sphere_p.h>
#include <Qt3DRender/qshaderdata.h>
#include <Qt3DRender/qgeometryrenderer.h>
#include <Qt3DRender/qobjectpicker.h>
#include <Qt3DRender/qcomputecommand.h>
#include <Qt3DRender/private/qboundingvolumedebug_p.h>
#include <Qt3DRender/private/geometryrenderermanager_p.h>

#include <Qt3DRender/qcameralens.h>
#include <Qt3DCore/qcomponentaddedchange.h>
#include <Qt3DCore/qcomponentremovedchange.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DCore/qnodepropertychange.h>
#include <Qt3DCore/qtransform.h>
#include <Qt3DCore/private/qentity_p.h>

#include <QMatrix4x4>
#include <QString>

QT_BEGIN_NAMESPACE

using namespace Qt3DCore;

namespace Qt3DRender {
namespace Render {

Entity::Entity()
    : BackendNode()
    , m_nodeManagers(Q_NULLPTR)
    , m_boundingDirty(false)
{
}

Entity::~Entity()
{
    cleanup();
}

void Entity::cleanup()
{
    if (m_nodeManagers != Q_NULLPTR) {
        Entity *parentEntity = parent();
        if (parentEntity != Q_NULLPTR)
            parentEntity->removeChildHandle(m_handle);
        for (int i = 0; i < m_childrenHandles.size(); i++)
            m_nodeManagers->renderNodesManager()->release(m_childrenHandles[i]);
        // We need to release using peerId otherwise the handle will be cleared
        // but would still remain in the Id to Handle table
        m_nodeManagers->worldMatrixManager()->releaseResource(peerId());

        qCDebug(Render::RenderNodes) << Q_FUNC_INFO;

    }
    m_worldTransform = HMatrix();
    // Release all component will have to perform their own release when they receive the
    // NodeDeleted/NodeAboutToBeDeleted notification
    // Clear components
    m_transformComponent = Qt3DCore::QNodeId();
    m_cameraComponent = Qt3DCore::QNodeId();
    m_materialComponent = Qt3DCore::QNodeId();
    m_geometryRendererComponent = Qt3DCore::QNodeId();
    m_objectPickerComponent = QNodeId();
    m_boundingVolumeDebugComponent = QNodeId();
    m_computeComponent = QNodeId();
    m_layerComponents.clear();
    m_shaderDataComponents.clear();
    m_lightComponents.clear();
    m_localBoundingVolume.reset();
    m_worldBoundingVolume.reset();
    m_worldBoundingVolumeWithChildren.reset();
    m_boundingDirty = false;
    QBackendNode::setEnabled(false);
}

void Entity::setParentHandle(HEntity parentHandle)
{
    Q_ASSERT(m_nodeManagers);
    // Remove ourselves from previous parent children list
    Entity *parent = m_nodeManagers->renderNodesManager()->data(parentHandle);
    if (parent != Q_NULLPTR && parent->m_childrenHandles.contains(m_handle))
        parent->m_childrenHandles.remove(m_handle);
    m_parentHandle = parentHandle;
    parent = m_nodeManagers->renderNodesManager()->data(parentHandle);
    if (parent != Q_NULLPTR && !parent->m_childrenHandles.contains(m_handle))
        parent->m_childrenHandles.append(m_handle);
}

void Entity::setNodeManagers(NodeManagers *manager)
{
    m_nodeManagers = manager;
}

void Entity::setHandle(HEntity handle)
{
    m_handle = handle;
}

void Entity::updateFromPeer(Qt3DCore::QNode *peer)
{
    QEntity *entity = static_cast<QEntity *>(peer);
    QEntityPrivate *entityPrivate = static_cast<QEntityPrivate *>(QNodePrivate::get(entity));
    const QNodeId parentEntityId = entityPrivate->parentEntityId();

    m_objectName = peer->objectName();
    m_worldTransform = m_nodeManagers->worldMatrixManager()->getOrAcquireHandle(peerId());

    // TO DO: Suboptimal -> Maybe have a Hash<QComponent, QEntityList> instead
    m_transformComponent = QNodeId();
    m_materialComponent = QNodeId();
    m_cameraComponent = QNodeId();
    m_geometryRendererComponent = QNodeId();
    m_objectPickerComponent = QNodeId();
    m_boundingVolumeDebugComponent = QNodeId();
    m_layerComponents.clear();
    m_shaderDataComponents.clear();
    m_lightComponents.clear();
    m_localBoundingVolume.reset(new Sphere(peerId()));
    m_worldBoundingVolume.reset(new Sphere(peerId()));
    m_worldBoundingVolumeWithChildren.reset(new Sphere(peerId()));

    Q_FOREACH (QComponent *comp, entity->components())
        addComponent(comp);

    if (!parentEntityId.isNull()) {
        setParentHandle(m_nodeManagers->renderNodesManager()->lookupHandle(parentEntityId));
    } else {
        qCDebug(Render::RenderNodes) << Q_FUNC_INFO << "No parent entity found for Entity" << peerId();
    }
}

void Entity::initializeFromPeer(const QNodeCreatedChangeBasePtr &change)
{
    const auto typedChange = qSharedPointerCast<QNodeCreatedChange<Qt3DCore::QEntityData>>(change);
    const auto &data = typedChange->data;

    // Note this is *not* the parentId as that is the ID of the parent QNode, which is not
    // necessarily the same as the parent QEntity (which may be further up the tree).
    const QNodeId parentEntityId = data.parentEntityId;
    qCDebug(Render::RenderNodes) << "Creating Entity id =" << peerId() << "parentId =" << parentEntityId;

    // TODO: Store string id instead and only in debug mode
    //m_objectName = peer->objectName();
    m_worldTransform = m_nodeManagers->worldMatrixManager()->getOrAcquireHandle(peerId());

    // TODO: Suboptimal -> Maybe have a Hash<QComponent, QEntityList> instead
    m_transformComponent = QNodeId();
    m_materialComponent = QNodeId();
    m_cameraComponent = QNodeId();
    m_geometryRendererComponent = QNodeId();
    m_objectPickerComponent = QNodeId();
    m_boundingVolumeDebugComponent = QNodeId();
    m_layerComponents.clear();
    m_shaderDataComponents.clear();
    m_lightComponents.clear();
    m_localBoundingVolume.reset(new Sphere(peerId()));
    m_worldBoundingVolume.reset(new Sphere(peerId()));
    m_worldBoundingVolumeWithChildren.reset(new Sphere(peerId()));

    for (const auto &idAndType : qAsConst(data.componentIdsAndTypes))
        addComponent(idAndType);

    if (!parentEntityId.isNull())
        setParentHandle(m_nodeManagers->renderNodesManager()->lookupHandle(parentEntityId));
    else
        qCDebug(Render::RenderNodes) << Q_FUNC_INFO << "No parent entity found for Entity" << peerId();
}

void Entity::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
{
    switch (e->type()) {

    case ComponentAdded: {
        QComponentAddedChangePtr change = qSharedPointerCast<QComponentAddedChange>(e);
        const auto componentIdAndType = QNodeIdTypePair(change->componentId(), change->componentMetaObject());
        addComponent(componentIdAndType);
        qCDebug(Render::RenderNodes) << Q_FUNC_INFO << "Component Added. Id =" << change->componentId();
        break;
    }

    case ComponentRemoved: {
        QComponentRemovedChangePtr change = qSharedPointerCast<QComponentRemovedChange>(e);
        removeComponent(change->componentId());
        qCDebug(Render::RenderNodes) << Q_FUNC_INFO << "Component Removed. Id =" << change->componentId();
        break;
    }

    default:
        break;
    }
    markDirty(AbstractRenderer::AllDirty);
    BackendNode::sceneChangeEvent(e);
}

void Entity::dump() const
{
    static int depth = 0;
    QString indent(2 * depth++, QChar::fromLatin1(' '));
    qCDebug(Backend) << indent + m_objectName;
    foreach (const Entity *child, children())
        child->dump();
    --depth;
}

Entity *Entity::parent() const
{
    return m_nodeManagers->renderNodesManager()->data(m_parentHandle);
}

void Entity::appendChildHandle(HEntity childHandle)
{
    if (!m_childrenHandles.contains(childHandle)) {
        m_childrenHandles.append(childHandle);
        Entity *child = m_nodeManagers->renderNodesManager()->data(childHandle);
        if (child != Q_NULLPTR)
            child->m_parentHandle = m_handle;
    }
}

void Entity::removeChildHandle(HEntity childHandle)
{
    // TO DO : Check if a QList here wouldn't be more performant
    if (m_childrenHandles.contains(childHandle)) {
        m_childrenHandles.removeAt(m_childrenHandles.indexOf(childHandle));
    }
}

QVector<Entity *> Entity::children() const
{
    QVector<Entity *> childrenVector;
    childrenVector.reserve(m_childrenHandles.size());
    foreach (HEntity handle, m_childrenHandles) {
        Entity *child = m_nodeManagers->renderNodesManager()->data(handle);
        if (child != Q_NULLPTR)
            childrenVector.append(child);
    }
    return childrenVector;
}

QMatrix4x4 *Entity::worldTransform()
{
    return m_nodeManagers->worldMatrixManager()->data(m_worldTransform);
}

const QMatrix4x4 *Entity::worldTransform() const
{
    return m_nodeManagers->worldMatrixManager()->data(m_worldTransform);
}

void Entity::addComponent(Qt3DCore::QComponent *component)
{
    // The backend element is always created when this method is called
    // If that's not the case something has gone wrong

    if (qobject_cast<Qt3DCore::QTransform*>(component) != Q_NULLPTR) {
        m_transformComponent = component->id();
    } else if (qobject_cast<QCameraLens *>(component) != Q_NULLPTR) {
        m_cameraComponent = component->id();
    } else if (qobject_cast<QLayer *>(component) != Q_NULLPTR) {
        m_layerComponents.append(component->id());
    } else if (qobject_cast<QMaterial *>(component) != Q_NULLPTR) {
        m_materialComponent = component->id();
    } else if (qobject_cast<QLight *>(component) != Q_NULLPTR) { // QLight subclasses QShaderData
        m_lightComponents.append(component->id());
    } else if (qobject_cast<QShaderData *>(component) != Q_NULLPTR) {
        m_shaderDataComponents.append(component->id());
    } else if (qobject_cast<QGeometryRenderer *>(component) != Q_NULLPTR) {
        m_geometryRendererComponent = component->id();
        m_boundingDirty = true;
    } else if (qobject_cast<QObjectPicker *>(component) != Q_NULLPTR) {
        m_objectPickerComponent = component->id();
//    } else if (qobject_cast<QBoundingVolumeDebug *>(component) != Q_NULLPTR) {
//        m_boundingVolumeDebugComponent = component->id();
    } else if (qobject_cast<QComputeCommand *>(component) != Q_NULLPTR) {
        m_computeComponent = component->id();
    }
}

void Entity::addComponent(Qt3DCore::QNodeIdTypePair idAndType)
{
    // The backend element is always created when this method is called
    // If that's not the case something has gone wrong
    const auto type = idAndType.type;
    const auto id = idAndType.id;
    qCDebug(Render::RenderNodes) << Q_FUNC_INFO << "id =" << id << type->className();
    if (type->inherits(&Qt3DCore::QTransform::staticMetaObject)) {
        m_transformComponent = id;
    } else if (type->inherits(&QCameraLens::staticMetaObject)) {
        m_cameraComponent = id;
    } else if (type->inherits(&QLayer::staticMetaObject)) {
        m_layerComponents.append(id);
    } else if (type->inherits(&QMaterial::staticMetaObject)) {
        m_materialComponent = id;
    } else if (type->inherits(&QLight::staticMetaObject)) { // QLight subclasses QShaderData
        m_lightComponents.append(id);
    } else if (type->inherits(&QShaderData::staticMetaObject)) {
        m_shaderDataComponents.append(id);
    } else if (type->inherits(&QGeometryRenderer::staticMetaObject)) {
        m_geometryRendererComponent = id;
        m_boundingDirty = true;
    } else if (type->inherits(&QObjectPicker::staticMetaObject)) {
        m_objectPickerComponent = id;
//    } else if (type->inherits(&QBoundingVolumeDebug::staticMetaObject)) {
//        m_boundingVolumeDebugComponent = id;
    } else if (type->inherits(&QComputeCommand::staticMetaObject)) {
        m_computeComponent = id;
    }
}

void Entity::removeComponent(Qt3DCore::QNodeId nodeId)
{
    if (m_transformComponent == nodeId) {
        m_transformComponent = QNodeId();
    } else if (m_cameraComponent == nodeId) {
        m_cameraComponent = QNodeId();
    } else if (m_layerComponents.contains(nodeId)) {
        m_layerComponents.removeAll(nodeId);
    } else if (m_materialComponent == nodeId) {
        m_materialComponent = QNodeId();
    } else if (m_shaderDataComponents.contains(nodeId)) {
        m_shaderDataComponents.removeAll(nodeId);
    } else if (m_geometryRendererComponent == nodeId) {
        m_geometryRendererComponent = QNodeId();
        m_boundingDirty = true;
    } else if (m_objectPickerComponent == nodeId) {
        m_objectPickerComponent = QNodeId();
//    } else if (m_boundingVolumeDebugComponent == nodeId) {
//        m_boundingVolumeDebugComponent = QNodeId();
    } else if (m_lightComponents.contains(nodeId)) {
        m_lightComponents.removeAll(nodeId);
    } else if (m_computeComponent == nodeId) {
        m_computeComponent = QNodeId();
    }
}

bool Entity::isBoundingVolumeDirty() const
{
    return m_boundingDirty;
}

void Entity::unsetBoundingVolumeDirty()
{
    m_boundingDirty = false;
}

// Handles

template<>
HMaterial Entity::componentHandle<Material>() const
{
    return m_nodeManagers->materialManager()->lookupHandle(m_materialComponent);
}

template<>
HCamera Entity::componentHandle<CameraLens>() const
{
    return m_nodeManagers->cameraManager()->lookupHandle(m_cameraComponent);
}

template<>
HTransform Entity::componentHandle<Transform>() const
{
    return m_nodeManagers->transformManager()->lookupHandle(m_transformComponent);
}

template<>
HGeometryRenderer Entity::componentHandle<GeometryRenderer>() const
{
    return m_nodeManagers->geometryRendererManager()->lookupHandle(m_geometryRendererComponent);
}

template<>
HObjectPicker Entity::componentHandle<ObjectPicker>() const
{
    return m_nodeManagers->objectPickerManager()->lookupHandle(m_objectPickerComponent);
}

template<>
QList<HLayer> Entity::componentsHandle<Layer>() const
{
    QList<HLayer> layerHandles;
    layerHandles.reserve(m_layerComponents.size());
    Q_FOREACH (QNodeId id, m_layerComponents)
        layerHandles.append(m_nodeManagers->layerManager()->lookupHandle(id));
    return layerHandles;
}

template<>
QList<HShaderData> Entity::componentsHandle<ShaderData>() const
{
    QList<HShaderData> shaderDataHandles;
    shaderDataHandles.reserve(m_shaderDataComponents.size());
    Q_FOREACH (QNodeId id, m_shaderDataComponents)
        shaderDataHandles.append(m_nodeManagers->shaderDataManager()->lookupHandle(id));
    return shaderDataHandles;
}

//template<>
//HBoundingVolumeDebug Entity::componentHandle<BoundingVolumeDebug>() const
//{
//    return m_nodeManagers->boundingVolumeDebugManager()->lookupHandle(m_boundingVolumeDebugComponent);
//}

template<>
QList<HLight> Entity::componentsHandle<Light>() const
{
    QList<HLight> lightHandles;
    lightHandles.reserve(m_lightComponents.size());
    Q_FOREACH (QNodeId id, m_lightComponents)
        lightHandles.append(m_nodeManagers->lightManager()->lookupHandle(id));
    return lightHandles;
}

template<>
HComputeCommand Entity::componentHandle<ComputeCommand>() const
{
    return m_nodeManagers->computeJobManager()->lookupHandle(m_computeComponent);
}

// Render components

template<>
Material *Entity::renderComponent<Material>() const
{
    return m_nodeManagers->materialManager()->lookupResource(m_materialComponent);
}

template<>
CameraLens *Entity::renderComponent<CameraLens>() const
{
    return m_nodeManagers->cameraManager()->lookupResource(m_cameraComponent);
}

template<>
Transform *Entity::renderComponent<Transform>() const
{
    return m_nodeManagers->transformManager()->lookupResource(m_transformComponent);
}

template<>
GeometryRenderer *Entity::renderComponent<GeometryRenderer>() const
{
    return m_nodeManagers->geometryRendererManager()->lookupResource(m_geometryRendererComponent);
}

template<>
ObjectPicker *Entity::renderComponent<ObjectPicker>() const
{
    return m_nodeManagers->objectPickerManager()->lookupResource(m_objectPickerComponent);
}

template<>
QList<Layer *> Entity::renderComponents<Layer>() const
{
    QList<Layer *> layers;
    layers.reserve(m_layerComponents.size());
    Q_FOREACH (QNodeId id, m_layerComponents)
        layers.append(m_nodeManagers->layerManager()->lookupResource(id));
    return layers;
}

template<>
QList<ShaderData *> Entity::renderComponents<ShaderData>() const
{
    QList<ShaderData *> shaderDatas;
    shaderDatas.reserve(m_shaderDataComponents.size());
    Q_FOREACH (QNodeId id, m_shaderDataComponents)
        shaderDatas.append(m_nodeManagers->shaderDataManager()->lookupResource(id));
    return shaderDatas;
}

template<>
QList<Light *> Entity::renderComponents<Light>() const
{
    QList<Light *> lights;
    lights.reserve(m_lightComponents.size());
    Q_FOREACH (QNodeId id, m_lightComponents)
        lights.append(m_nodeManagers->lightManager()->lookupResource(id));
    return lights;
}

//template<>
//BoundingVolumeDebug *Entity::renderComponent<BoundingVolumeDebug>() const
//{
//    return m_nodeManagers->boundingVolumeDebugManager()->lookupResource(m_boundingVolumeDebugComponent);
//}

template<>
ComputeCommand *Entity::renderComponent<ComputeCommand>() const
{
    return m_nodeManagers->computeJobManager()->lookupResource(m_computeComponent);
}

// Uuid

template<>
Qt3DCore::QNodeId Entity::componentUuid<Transform>() const { return m_transformComponent; }

template<>
Qt3DCore::QNodeId Entity::componentUuid<CameraLens>() const { return m_cameraComponent; }

template<>
Qt3DCore::QNodeId Entity::componentUuid<Material>() const { return m_materialComponent; }

template<>
QVector<Qt3DCore::QNodeId> Entity::componentsUuid<Layer>() const { return m_layerComponents; }

template<>
QVector<Qt3DCore::QNodeId> Entity::componentsUuid<ShaderData>() const { return m_shaderDataComponents; }

template<>
Qt3DCore::QNodeId Entity::componentUuid<GeometryRenderer>() const { return m_geometryRendererComponent; }

template<>
QNodeId Entity::componentUuid<ObjectPicker>() const { return m_objectPickerComponent; }

template<>
QNodeId Entity::componentUuid<BoundingVolumeDebug>() const { return m_boundingVolumeDebugComponent; }

template<>
QNodeId Entity::componentUuid<ComputeCommand>() const { return m_computeComponent; }

template<>
QVector<Qt3DCore::QNodeId> Entity::componentsUuid<Light>() const { return m_lightComponents; }

RenderEntityFunctor::RenderEntityFunctor(AbstractRenderer *renderer, NodeManagers *manager)
    : m_nodeManagers(manager)
    , m_renderer(renderer)
{
}

Qt3DCore::QBackendNode *RenderEntityFunctor::create(Qt3DCore::QNode *frontend) const
{
    HEntity renderNodeHandle = m_nodeManagers->renderNodesManager()->getOrAcquireHandle(frontend->id());
    Entity *entity = m_nodeManagers->renderNodesManager()->data(renderNodeHandle);
    entity->setNodeManagers(m_nodeManagers);
    entity->setHandle(renderNodeHandle);
    entity->setPeer(frontend);
    entity->setRenderer(m_renderer);
    return entity;
}

Qt3DCore::QBackendNode *RenderEntityFunctor::create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const
{
    HEntity renderNodeHandle = m_nodeManagers->renderNodesManager()->getOrAcquireHandle(change->subjectId());
    Entity *entity = m_nodeManagers->renderNodesManager()->data(renderNodeHandle);
    entity->setNodeManagers(m_nodeManagers);
    entity->setHandle(renderNodeHandle);
    entity->setRenderer(m_renderer);
    return entity;
}

Qt3DCore::QBackendNode *RenderEntityFunctor::get(Qt3DCore::QNodeId id) const
{
    return m_nodeManagers->renderNodesManager()->lookupResource(id);
}

void RenderEntityFunctor::destroy(Qt3DCore::QNodeId id) const
{
    m_nodeManagers->renderNodesManager()->releaseResource(id);
}

} // namespace Render
} // namespace Qt3DRender

QT_END_NAMESPACE