1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DRENDER_RENDER_BUFFER_H
5#define QT3DRENDER_RENDER_BUFFER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore>
19#include <Qt3DRender/private/backendnode_p.h>
20#include <Qt3DCore/qbuffer.h>
21
22QT_BEGIN_NAMESPACE
23
24namespace Qt3DCore {
25 struct QBufferUpdate;
26}
27
28namespace Qt3DRender {
29namespace Render {
30
31class BufferManager;
32
33class Q_3DRENDERSHARED_PRIVATE_EXPORT Buffer : public BackendNode
34{
35public:
36 Buffer();
37 ~Buffer();
38 void cleanup();
39
40 void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
41
42 void setManager(BufferManager *manager);
43 void updateDataFromGPUToCPU(QByteArray data);
44 inline Qt3DCore::QBuffer::UsageType usage() const { return m_usage; }
45 inline QByteArray data() const { return m_data; }
46 inline std::vector<Qt3DCore::QBufferUpdate> &pendingBufferUpdates() { return m_bufferUpdates; }
47 inline bool isDirty() const { return m_bufferDirty; }
48 inline Qt3DCore::QBuffer::AccessType access() const { return m_access; }
49 void unsetDirty();
50
51private:
52 void forceDataUpload();
53
54 Qt3DCore::QBuffer::UsageType m_usage;
55 QByteArray m_data;
56 std::vector<Qt3DCore::QBufferUpdate> m_bufferUpdates;
57 bool m_bufferDirty;
58 Qt3DCore::QBuffer::AccessType m_access;
59 BufferManager *m_manager;
60};
61
62class BufferFunctor : public Qt3DCore::QBackendNodeMapper
63{
64public:
65 explicit BufferFunctor(AbstractRenderer *renderer, BufferManager *manager);
66 Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const override;
67 Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override;
68 void destroy(Qt3DCore::QNodeId id) const override;
69private:
70 BufferManager *m_manager;
71 AbstractRenderer *m_renderer;
72};
73
74} // namespace Render
75} // namespace Qt3DRender
76
77QT_END_NAMESPACE
78
79#endif // QT3DRENDER_RENDER_BUFFER_H
80

source code of qt3d/src/render/geometry/buffer_p.h