1 | // Copyright (C) 2016 Paul Lemire |
2 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #ifndef QT3DRENDER_RENDER_RENDERVIEWINITIALIZERJOB_H |
6 | #define QT3DRENDER_RENDER_RENDERVIEWINITIALIZERJOB_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists for the convenience |
13 | // of other Qt classes. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <Qt3DCore/qaspectjob.h> |
20 | #include <Qt3DRender/private/renderlogging_p.h> |
21 | #include <Qt3DRender/private/job_common_p.h> |
22 | #include <QSize> |
23 | #include <QElapsedTimer> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | namespace Qt3DRender { |
28 | |
29 | namespace Render { |
30 | |
31 | class FrameGraphNode; |
32 | |
33 | template<class RenderView, class Renderer> |
34 | class RenderViewInitializerJob : public Qt3DCore::QAspectJob |
35 | { |
36 | public: |
37 | RenderViewInitializerJob() |
38 | : Qt3DCore::QAspectJob() |
39 | { |
40 | SET_JOB_RUN_STAT_TYPE(this, JobTypes::RenderView, RenderViewInitializerJob::renderViewInstanceCounter++) |
41 | } |
42 | ~RenderViewInitializerJob() |
43 | { |
44 | RenderViewInitializerJob::renderViewInstanceCounter--; |
45 | } |
46 | |
47 | inline void setRenderer(Renderer *renderer) { m_renderer = renderer; } |
48 | inline RenderView *renderView() const noexcept { return m_renderView; } |
49 | |
50 | inline void setFrameGraphLeafNode(FrameGraphNode *fgLeaf) |
51 | { |
52 | m_fgLeaf = fgLeaf; |
53 | } |
54 | |
55 | // Sets the position in the queue of RenderViews that the |
56 | // RenderView generated by this job should be inserted. This is |
57 | // used to ensure that for example a RenderView for creating |
58 | // a shadow map texture is submitted before the RenderView that |
59 | // contains commands making use of the shadow map |
60 | inline void setSubmitOrderIndex(int index) { m_index = index; } |
61 | inline int submitOrderIndex() const { return m_index; } |
62 | |
63 | void run() override |
64 | { |
65 | #if defined(QT3D_RENDER_VIEW_JOB_TIMINGS) |
66 | QElapsedTimer timer; |
67 | timer.start(); |
68 | qint64 gatherLightsTime; |
69 | qint64 buildCommandsTime; |
70 | #endif |
71 | |
72 | // Create a RenderView object |
73 | m_renderView = new RenderView; |
74 | m_renderView->setRenderer(m_renderer); |
75 | |
76 | // Populate the renderview's configuration from the framegraph |
77 | RenderView::setRenderViewConfigFromFrameGraphLeafNode(m_renderView, m_fgLeaf); |
78 | #if defined(QT3D_RENDER_VIEW_JOB_TIMINGS) |
79 | qint64 gatherStateTime = timer.nsecsElapsed(); |
80 | timer.restart(); |
81 | #endif |
82 | } |
83 | |
84 | private: |
85 | Renderer *m_renderer = nullptr; |
86 | FrameGraphNode *m_fgLeaf = nullptr; |
87 | RenderView *m_renderView = nullptr; |
88 | int m_index = 0; |
89 | |
90 | static int renderViewInstanceCounter; |
91 | }; |
92 | |
93 | template<class RenderView, class Renderer> |
94 | int RenderViewInitializerJob<RenderView, Renderer>::renderViewInstanceCounter = 0; |
95 | |
96 | template<class RenderView, class Renderer> |
97 | using RenderViewInitializerJobPtr = QSharedPointer<RenderViewInitializerJob<RenderView, Renderer>>; |
98 | |
99 | } // namespace Render |
100 | } // namespace Qt3DRender |
101 | |
102 | QT_END_NAMESPACE |
103 | |
104 | #endif // QT3DRENDER_RENDER_RENDERVIEWINITIALIZERJOB_H |
105 | |