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_FRUSTUMCULLINGJOB_P_H
5#define QT3DRENDER_RENDER_FRUSTUMCULLINGJOB_P_H
6
7#include <Qt3DCore/qaspectjob.h>
8#include <Qt3DCore/private/matrix4x4_p.h>
9#include <Qt3DCore/private/vector3d_p.h>
10#include <Qt3DCore/private/vector4d_p.h>
11#include <Qt3DCore/private/aligned_malloc_p.h>
12#include <Qt3DRender/private/qt3drender_global_p.h>
13
14//
15// W A R N I N G
16// -------------
17//
18// This file is not part of the Qt API. It exists for the convenience
19// of other Qt classes. This header file may change from version to
20// version without notice, or even be removed.
21//
22// We mean it.
23//
24
25QT_BEGIN_NAMESPACE
26
27namespace Qt3DRender {
28
29namespace Render {
30
31class Entity;
32class EntityManager;
33class NodeManagers;
34struct Plane;
35
36class Q_3DRENDERSHARED_PRIVATE_EXPORT FrustumCullingJob : public Qt3DCore::QAspectJob
37{
38public:
39 FrustumCullingJob();
40 ~FrustumCullingJob();
41
42 QT3D_ALIGNED_MALLOC_AND_FREE()
43
44 inline void setRoot(Entity *root) noexcept { m_root = root; }
45 inline void setManagers(NodeManagers *manager) noexcept { m_manager = manager; }
46 inline void setActive(bool active) noexcept { m_active = active; }
47 inline bool isActive() const noexcept { return m_active; }
48 inline void setViewProjection(const Matrix4x4 &viewProjection) noexcept { m_viewProjection = viewProjection; }
49 inline Matrix4x4 viewProjection() const noexcept { return m_viewProjection; }
50 bool isRequired() override;
51
52 const std::vector<Entity *> &visibleEntities() const noexcept { return m_visibleEntities; }
53
54 void run() final;
55
56private:
57 struct Q_AUTOTEST_EXPORT Plane
58 {
59 explicit Plane(const Vector4D &planeEquation)
60 : planeEquation(planeEquation)
61 , normal(Vector3D(planeEquation).normalized())
62 , d(planeEquation.w() / Vector3D(planeEquation).length())
63 {}
64
65 const Vector4D planeEquation;
66 const Vector3D normal;
67 const float d;
68 };
69
70 void cullScene(Entity *e, const Plane *planes);
71 Matrix4x4 m_viewProjection;
72 Entity *m_root;
73 NodeManagers *m_manager;
74 std::vector<Entity *> m_visibleEntities;
75 bool m_active;
76};
77
78typedef QSharedPointer<FrustumCullingJob> FrustumCullingJobPtr;
79
80} // Render
81
82} // Qt3DRender
83
84QT_END_NAMESPACE
85
86#endif // QT3DRENDER_RENDER_FRUSTUMCULLINGJOB_P_H
87

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