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 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | namespace Qt3DRender { |
28 | |
29 | namespace Render { |
30 | |
31 | class Entity; |
32 | class EntityManager; |
33 | class NodeManagers; |
34 | struct Plane; |
35 | |
36 | class Q_3DRENDERSHARED_PRIVATE_EXPORT FrustumCullingJob : public Qt3DCore::QAspectJob |
37 | { |
38 | public: |
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 | |
56 | private: |
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 | |
78 | typedef QSharedPointer<FrustumCullingJob> FrustumCullingJobPtr; |
79 | |
80 | } // Render |
81 | |
82 | } // Qt3DRender |
83 | |
84 | QT_END_NAMESPACE |
85 | |
86 | #endif // QT3DRENDER_RENDER_FRUSTUMCULLINGJOB_P_H |
87 |