1// Copyright (C) 2016 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_OPENGL_RENDERVIEWBUILDER_H
5#define QT3DRENDER_RENDER_OPENGL_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 OpenGL {
39
40class Renderer;
41
42using SynchronizerJobPtr = GenericLambdaJobPtr<std::function<void()>>;
43#define CreateSynchronizerJobPtr(lambda, type, instance) \
44 SynchronizerJobPtr::create(lambda, type, #type, instance)
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 setClearDrawBufferIndexJob() const;
67 SynchronizerJobPtr syncFilterEntityByLayerJob() const;
68 FilterProximityDistanceJobPtr filterProximityJob() const;
69 SynchronizerJobPtr syncMaterialGathererJob() const;
70
71 void prepareJobs();
72 std::vector<Qt3DCore::QAspectJobPtr> buildJobHierachy() const;
73
74 Renderer *renderer() const;
75 int renderViewIndex() const;
76
77 void setLayerCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
78 bool layerCacheNeedsToBeRebuilt() const;
79 void setMaterialGathererCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
80 bool materialGathererCacheNeedsToBeRebuilt() const;
81 void setRenderCommandCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
82 bool renderCommandCacheNeedsToBeRebuilt() const;
83 void setLightCacheNeedsToBeRebuilt(bool needsToBeRebuilt);
84 bool lightCacheNeedsToBeRebuilt() const;
85
86 int optimalJobCount() const;
87 void setOptimalJobCount(int v);
88
89private:
90 Render::FrameGraphNode *m_leafNode;
91 const int m_renderViewIndex;
92 Renderer *m_renderer;
93 RebuildFlagSet m_rebuildFlags;
94
95 RenderViewInitializerJobPtr m_renderViewJob;
96 FilterLayerEntityJobPtr m_filterEntityByLayerJob;
97 FrustumCullingJobPtr m_frustumCullingJob;
98 std::vector<RenderViewCommandBuilderJobPtr> m_renderViewCommandBuilderJobs;
99 std::vector<RenderViewCommandUpdaterJobPtr> m_renderViewCommandUpdaterJobs;
100 std::vector<MaterialParameterGathererJobPtr> m_materialGathererJobs;
101
102 SynchronizerJobPtr m_syncRenderViewPostInitializationJob;
103 SynchronizerJobPtr m_syncPreFrustumCullingJob;
104 SynchronizerJobPtr m_syncRenderViewPreCommandBuildingJob;
105 SynchronizerJobPtr m_syncRenderViewPreCommandUpdateJob;
106 SynchronizerJobPtr m_syncRenderViewPostCommandUpdateJob;
107 SynchronizerJobPtr m_setClearDrawBufferIndexJob;
108 SynchronizerJobPtr m_syncFilterEntityByLayerJob;
109 SynchronizerJobPtr m_syncMaterialGathererJob;
110 FilterProximityDistanceJobPtr m_filterProximityJob;
111
112 int m_optimalParallelJobCount;
113};
114
115} // OpenGL
116
117} // Render
118
119} // Qt3DRender
120
121QT_END_NAMESPACE
122
123#endif // QT3DRENDER_RENDER_OPENGL_RENDERVIEWBUILDER_H
124

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