1// Copyright (C) 2015 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 "buffermanager_p.h"
5
6QT_BEGIN_NAMESPACE
7
8namespace Qt3DRender {
9namespace Render {
10
11BufferManager::BufferManager()
12{
13}
14
15BufferManager::~BufferManager()
16{
17}
18
19void BufferManager::addDirtyBuffer(Qt3DCore::QNodeId bufferId)
20{
21 if (!m_dirtyBuffers.contains(t: bufferId))
22 m_dirtyBuffers.push_back(t: bufferId);
23}
24
25QList<Qt3DCore::QNodeId> BufferManager::takeDirtyBuffers()
26{
27 return qMove(m_dirtyBuffers);
28}
29
30// Called in QAspectThread::syncChanges
31void BufferManager::removeBufferReference(Qt3DCore::QNodeId bufferId)
32{
33 QMutexLocker lock(&m_mutex);
34 Q_ASSERT(m_bufferReferences.contains(bufferId) && m_bufferReferences[bufferId] > 0);
35 m_bufferReferences[bufferId]--;
36}
37
38// Called in QAspectThread
39void BufferManager::addBufferReference(Qt3DCore::QNodeId bufferId)
40{
41 QMutexLocker lock(&m_mutex);
42 m_bufferReferences[bufferId]++;
43}
44
45// Called in Render thread
46QList<Qt3DCore::QNodeId> BufferManager::takeBuffersToRelease()
47{
48 QMutexLocker lock(&m_mutex);
49 QList<Qt3DCore::QNodeId> buffersToRelease;
50 for (auto it = m_bufferReferences.begin(), end = m_bufferReferences.end(); it != end; /*erasing*/) {
51 if (it.value() == 0) {
52 buffersToRelease.append(t: it.key());
53 it = m_bufferReferences.erase(it);
54 } else {
55 ++it;
56 }
57 }
58 return buffersToRelease;
59}
60
61} // namespace Render
62} // namespace Qt3DRender
63
64QT_END_NAMESPACE
65

source code of qt3d/src/render/geometry/buffermanager.cpp