1 | // Copyright (C) 2019 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_RENDERVIEWCOMMANDBUILDERJOB_P_H |
5 | #define QT3DRENDER_RENDER_RENDERVIEWCOMMANDBUILDERJOB_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/qaspectjob.h> |
19 | #include <Qt3DRender/private/handle_types_p.h> |
20 | #include <Qt3DRender/private/renderercache_p.h> |
21 | #include <Qt3DRender/private/job_common_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | namespace Qt3DRender { |
26 | |
27 | namespace Render { |
28 | |
29 | template<class RenderView, class RenderCommand> |
30 | class RenderViewCommandBuilderJob : public Qt3DCore::QAspectJob |
31 | { |
32 | public: |
33 | RenderViewCommandBuilderJob() |
34 | { |
35 | SET_JOB_RUN_STAT_TYPE(this, JobTypes::RenderViewCommandBuilder, RenderViewCommandBuilderJob::renderViewInstanceCounter++) |
36 | } |
37 | |
38 | inline void setRenderView(RenderView *rv) noexcept { m_renderView = rv; } |
39 | inline void setEntities(const Entity **entities, int offset, int count) |
40 | { |
41 | m_offset = offset; |
42 | m_count = count; |
43 | m_entities = entities; |
44 | } |
45 | inline EntityRenderCommandData<RenderCommand> &commandData() { return m_commandData; } |
46 | |
47 | void run() final |
48 | { |
49 | const bool isDraw = !m_renderView->isCompute(); |
50 | if (isDraw) |
51 | m_commandData = m_renderView->buildDrawRenderCommands(m_entities, m_offset, m_count); |
52 | else |
53 | m_commandData = m_renderView->buildComputeRenderCommands(m_entities, m_offset, m_count); |
54 | } |
55 | |
56 | bool isRequired() override |
57 | { |
58 | return m_renderView && !m_renderView->noDraw() && m_count > 0; |
59 | } |
60 | |
61 | void postFrame(Qt3DCore::QAspectEngine *engine) override |
62 | { |
63 | Q_UNUSED(engine); |
64 | RenderViewCommandBuilderJob::renderViewInstanceCounter = 0; |
65 | } |
66 | |
67 | private: |
68 | RenderView *m_renderView = nullptr; |
69 | const Entity **m_entities = nullptr; |
70 | EntityRenderCommandData<RenderCommand> m_commandData; |
71 | int m_offset = 0; |
72 | int m_count = 0; |
73 | static int renderViewInstanceCounter; |
74 | }; |
75 | |
76 | template<class RenderView, class RenderCommand> |
77 | int RenderViewCommandBuilderJob<RenderView, RenderCommand>::renderViewInstanceCounter = 0; |
78 | |
79 | template<class RenderView, class RenderCommand> |
80 | using RenderViewCommandBuilderJobPtr = QSharedPointer<RenderViewCommandBuilderJob<RenderView, RenderCommand>>; |
81 | |
82 | } // Render |
83 | |
84 | } // Qt3DRender |
85 | |
86 | QT_END_NAMESPACE |
87 | |
88 | #endif // QT3DRENDER_RENDER_RENDERVIEWCOMMANDBUILDERJOB_P_H |
89 | |