1// Copyright (C) 2016 Paul Lemire
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_RENDERVIEWCOMMANDUPDATEJOB_P_H
5#define QT3DRENDER_RENDER_RENDERVIEWCOMMANDUPDATEJOB_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
23QT_BEGIN_NAMESPACE
24
25namespace Qt3DRender {
26
27namespace Render {
28
29template<class RenderView, class RenderCommand>
30class RenderViewCommandUpdaterJob : public Qt3DCore::QAspectJob
31{
32public:
33 RenderViewCommandUpdaterJob()
34 : Qt3DCore::QAspectJob()
35 {
36 SET_JOB_RUN_STAT_TYPE(this, JobTypes::RenderCommandUpdater, renderViewInstanceCounter++)
37 }
38
39 ~RenderViewCommandUpdaterJob()
40 {
41 }
42
43 inline void setRenderView(RenderView *rv) noexcept { m_renderView = rv; }
44 inline void setRenderablesSubView(const EntityRenderCommandDataSubView<RenderCommand> &renderablesSubView) noexcept
45 {
46 m_renderablesSubView = renderablesSubView;
47 }
48 EntityRenderCommandDataSubView<RenderCommand> renderablesSubView() const { return m_renderablesSubView; }
49
50 void run() final
51 {
52 // Build RenderCommand should perform the culling as we have no way to determine
53 // if a child has a mesh in the view frustum while its parent isn't contained in it.
54 if (!m_renderView->noDraw()) {
55 if (m_renderablesSubView.count == 0)
56 return;
57 // Update Render Commands (Uniform Change, Depth Change)
58 m_renderView->updateRenderCommand(m_renderablesSubView);
59 }
60 }
61
62 void postFrame(Qt3DCore::QAspectEngine *aspectEngine) override
63 {
64 Q_UNUSED(aspectEngine);
65 // reset to 0 after every frame, stops the number growing indefinitely
66 renderViewInstanceCounter = 0;
67 }
68
69 bool isRequired() override
70 {
71 return m_renderView && !m_renderView->noDraw() && m_renderablesSubView.count > 0;
72 }
73
74private:
75 RenderView *m_renderView = nullptr;
76 EntityRenderCommandDataSubView<RenderCommand> m_renderablesSubView;
77 static int renderViewInstanceCounter;
78};
79
80template<class RenderView, class RenderCommand>
81int RenderViewCommandUpdaterJob<RenderView, RenderCommand>::renderViewInstanceCounter = 0;
82
83template<class RenderView, class RenderCommand>
84using RenderViewCommandUpdaterJobPtr = QSharedPointer<RenderViewCommandUpdaterJob<RenderView, RenderCommand>>;
85
86} // Render
87
88} // Qt3DRender
89
90QT_END_NAMESPACE
91
92#endif // QT3DRENDER_RENDER_RENDERVIEWCOMMANDUPDATEJOB_P_H
93

source code of qt3d/src/render/jobs/renderviewcommandupdaterjob_p.h