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_RENDERVIEWBUILDER_H
5#define QT3DRENDER_RENDER_RHI_RENDERVIEWBUILDER_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 <functional>
19#include <Qt3DCore/qaspectjob.h>
20#include <Qt3DRender/private/filterlayerentityjob_p.h>
21#include <Qt3DRender/private/genericlambdajob_p.h>
22#include <Qt3DRender/private/nodemanagers_p.h>
23#include <Qt3DRender/private/frustumcullingjob_p.h>
24#include <Qt3DRender/private/filterproximitydistancejob_p.h>
25#include <Qt3DRender/private/materialparametergathererjob_p.h>
26#include <Qt3DRender/private/renderviewcommandbuilderjob_p.h>
27#include <Qt3DRender/private/renderviewcommandupdaterjob_p.h>
28#include <Qt3DRender/private/rendersyncjobs_p.h>
29#include <rendercommand_p.h>
30#include <renderview_p.h>
31
32QT_BEGIN_NAMESPACE
33
34namespace Qt3DRender {
35
36namespace Render {
37
38namespace Rhi {
39
40class Renderer;
41
42using SynchronizerJobPtr = GenericLambdaJobPtr<std::function<void()>>;
43#define CreateSynchronizerJobPtr(lambda, type) \
44 SynchronizerJobPtr::create(lambda, type, #type)
45
46using RenderViewCommandBuilderJobPtr = Render::RenderViewCommandBuilderJobPtr<RenderView, RenderCommand>;
47using RenderViewCommandUpdaterJobPtr = Render::RenderViewCommandUpdaterJobPtr<RenderView, RenderCommand>;
48using RenderViewInitializerJobPtr = Render::RenderViewInitializerJobPtr<RenderView, Renderer>;
49
50class Q_AUTOTEST_EXPORT RenderViewBuilder
51{
52public:
53 explicit RenderViewBuilder(Render::FrameGraphNode *leafNode, int renderViewIndex, Renderer *renderer);
54
55 RenderViewInitializerJobPtr renderViewJob() const;
56 FilterLayerEntityJobPtr filterEntityByLayerJob() const;
57 FrustumCullingJobPtr frustumCullingJob() const;
58 const std::vector<RenderViewCommandBuilderJobPtr> &renderViewCommandBuilderJobs() const;
59 const std::vector<RenderViewCommandUpdaterJobPtr> &renderViewCommandUpdaterJobs() const;
60 const std::vector<MaterialParameterGathererJobPtr> &materialGathererJobs() const;
61 SynchronizerJobPtr syncRenderViewPostInitializationJob() const;
62 SynchronizerJobPtr syncPreFrustumCullingJob() const;
63 SynchronizerJobPtr syncRenderViewPreCommandBuildingJob() const;
64 SynchronizerJobPtr syncRenderViewPreCommandUpdateJob() const;
65 SynchronizerJobPtr syncRenderViewPostCommandUpdateJob() const;
66 SynchronizerJobPtr syncFilterEntityByLayerJob() const;
67 FilterProximityDistanceJobPtr filterProximityJob() const;
68 SynchronizerJobPtr syncMaterialGathererJob() const;
69
70 void prepareJobs();
71 std::vector<Qt3DCore::QAspectJobPtr> buildJobHierachy() const;
72
73 Renderer *renderer() const;
74 int renderViewIndex() const;
75
76 void setLayerCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
77 bool layerCacheNeedsToBeRebuilt() const;
78 void setMaterialGathererCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
79 bool materialGathererCacheNeedsToBeRebuilt() const;
80 void setRenderCommandCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
81 bool renderCommandCacheNeedsToBeRebuilt() const;
82 void setLightCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
83 bool lightCacheNeedsToBeRebuilt() const;
84
85 int optimalJobCount() const;
86 void setOptimalJobCount(int v);
87
88private:
89 Render::FrameGraphNode *m_leafNode;
90 const int m_renderViewIndex;
91 Renderer *m_renderer;
92 RebuildFlagSet m_rebuildFlags;
93
94 RenderViewInitializerJobPtr m_renderViewJob;
95 FilterLayerEntityJobPtr m_filterEntityByLayerJob;
96 FrustumCullingJobPtr m_frustumCullingJob;
97 std::vector<RenderViewCommandBuilderJobPtr> m_renderViewCommandBuilderJobs;
98 std::vector<RenderViewCommandUpdaterJobPtr> m_renderViewCommandUpdaterJobs;
99 std::vector<MaterialParameterGathererJobPtr> m_materialGathererJobs;
100
101 SynchronizerJobPtr m_syncRenderViewPostInitializationJob;
102 SynchronizerJobPtr m_syncPreFrustumCullingJob;
103 SynchronizerJobPtr m_syncRenderViewPreCommandBuildingJob;
104 SynchronizerJobPtr m_syncRenderViewPreCommandUpdateJob;
105 SynchronizerJobPtr m_syncRenderViewPostCommandUpdateJob;
106 SynchronizerJobPtr m_syncFilterEntityByLayerJob;
107 SynchronizerJobPtr m_syncMaterialGathererJob;
108 FilterProximityDistanceJobPtr m_filterProximityJob;
109
110 int m_optimalParallelJobCount;
111};
112
113} // Rhi
114
115} // Render
116
117} // Qt3DRender
118
119QT_END_NAMESPACE
120
121#endif // QT3DRENDER_RENDER_RHI_RENDERVIEWBUILDER_H
122

source code of qt3d/src/plugins/renderers/rhi/renderer/renderviewbuilder_p.h