1 | // Copyright (C) 2020 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_RHI_RHIBUFFER_P_H |
5 | #define QT3DRENDER_RENDER_RHI_RHIBUFFER_P_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 <Qt3DCore/qnodeid.h> |
19 | #include <qbytearray.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | class QRhiBuffer; |
23 | namespace Qt3DRender { |
24 | |
25 | namespace Render { |
26 | |
27 | namespace Rhi { |
28 | |
29 | class SubmissionContext; |
30 | |
31 | class RHIBuffer |
32 | { |
33 | public: |
34 | RHIBuffer(); |
35 | |
36 | enum Type { |
37 | ArrayBuffer = 1 << 0, |
38 | UniformBuffer = 1 << 1, |
39 | IndexBuffer = 1 << 2, |
40 | ShaderStorageBuffer = 1 << 3, |
41 | PixelPackBuffer = 1 << 4, |
42 | PixelUnpackBuffer = 1 << 5, |
43 | DrawIndirectBuffer = 1 << 6 |
44 | }; |
45 | |
46 | bool bind(SubmissionContext *ctx, Type t); |
47 | void destroy(); |
48 | void destroyOrphaned(); |
49 | void allocate(const QByteArray &data, bool dynamic = true); |
50 | void update(const QByteArray &data, int offset = 0); |
51 | QByteArray download(SubmissionContext *ctx, uint size); |
52 | void cleanup(); |
53 | |
54 | qsizetype size() const { return m_allocSize; } |
55 | QRhiBuffer *rhiBuffer() const noexcept { return m_rhiBuffer; } |
56 | |
57 | private: |
58 | void orphan(); |
59 | |
60 | uint m_bufferId; |
61 | bool m_dynamic; |
62 | qsizetype m_allocSize {}; |
63 | |
64 | QRhiBuffer *m_rhiBuffer {}; |
65 | |
66 | std::vector<QRhiBuffer *> m_buffersToCleanup; |
67 | |
68 | std::vector<std::pair<QByteArray /*data*/, int /*offset*/>> m_datasToUpload; |
69 | }; |
70 | |
71 | } // namespace Rhi |
72 | |
73 | } // namespace Render |
74 | |
75 | } // namespace Qt3DRender |
76 | |
77 | QT_END_NAMESPACE |
78 | |
79 | #endif // QT3DRENDER_RENDER_RHI_RHIBUFFER_P_H |
80 | |