1/****************************************************************************
2**
3** Copyright (C) 2015 Paul Lemire
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "loadbufferjob_p.h"
41#include <Qt3DRender/private/buffer_p.h>
42#include <Qt3DRender/private/qbuffer_p.h>
43#include <Qt3DRender/private/buffermanager_p.h>
44#include <Qt3DRender/private/job_common_p.h>
45#include <Qt3DCore/private/qaspectmanager_p.h>
46#include <Qt3DRender/private/renderlogging_p.h>
47
48QT_BEGIN_NAMESPACE
49
50namespace Qt3DRender {
51
52namespace Render {
53
54class LoadBufferJobPrivate : public Qt3DCore::QAspectJobPrivate
55{
56public:
57 LoadBufferJobPrivate() {}
58 ~LoadBufferJobPrivate() {}
59
60 void postFrame(Qt3DCore::QAspectManager *aspectManager) override;
61
62 Buffer *m_bufferToUpdate = nullptr;
63};
64
65
66LoadBufferJob::LoadBufferJob(const HBuffer &handle)
67 : QAspectJob(*new LoadBufferJobPrivate)
68 , m_handle(handle)
69 , m_nodeManagers(nullptr)
70{
71 SET_JOB_RUN_STAT_TYPE(this, JobTypes::LoadBuffer, 0)
72}
73
74LoadBufferJob::~LoadBufferJob()
75{
76}
77
78void LoadBufferJob::run()
79{
80 Q_D(LoadBufferJob);
81 // Let's leave it for the moment until this has been properly tested
82 qCDebug(Jobs) << Q_FUNC_INFO;
83 Buffer *buffer = m_nodeManagers->data<Buffer, BufferManager>(handle: m_handle);
84 buffer->executeFunctor();
85 if (buffer->isSyncData())
86 d->m_bufferToUpdate = buffer;
87}
88
89void LoadBufferJobPrivate::postFrame(Qt3DCore::QAspectManager *aspectManager)
90{
91 if (m_bufferToUpdate == nullptr)
92 return;
93 QBuffer *frontendBuffer = static_cast<decltype(frontendBuffer)>(aspectManager->lookupNode(id: m_bufferToUpdate->peerId()));
94 QBufferPrivate *dFrontend = static_cast<decltype(dFrontend)>(Qt3DCore::QNodePrivate::get(q: frontendBuffer));
95 // Calling frontendBuffer->setData would result in forcing a sync against the backend
96 // which isn't necessary
97 dFrontend->setData(m_bufferToUpdate->data());
98 m_bufferToUpdate = nullptr;
99}
100
101} // namespace Render
102
103} // namespace Qt3DRender
104
105QT_END_NAMESPACE
106

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