1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef SCENEEFFECTS_H
5#define SCENEEFFECTS_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 purely as an
12// implementation detail. 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 <QtQuick3D/private/qquick3deffect_p.h>
19#include <QtQuick3D/private/qquick3dsceneenvironment_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class QQuick3DSceneEnvironment;
24class SceneEffectEnvironment;
25
26class SceneEffectBase : public QQuick3DEffect
27{
28 Q_OBJECT
29 Q_PROPERTY(QQuick3DSceneEnvironment * environment READ environment WRITE setEnvironment NOTIFY environmentChanged)
30 QML_NAMED_ELEMENT(SceneEffectBase)
31 QML_UNCREATABLE("SceneEffectBase is Abstract")
32public:
33 explicit SceneEffectBase(QQuick3DObject *parent = nullptr);
34
35 QQuick3DSceneEnvironment *environment() const;
36 void setEnvironment(QQuick3DSceneEnvironment *newEnvironment);
37
38signals:
39 void environmentChanged();
40
41protected:
42 void scheduleEnvUpdate();
43
44private:
45 QQuick3DSceneEnvironment *m_environment = nullptr;
46 virtual void registerWithEnv(SceneEffectEnvironment *newEnvironment) = 0;
47 virtual void unregisterWithEnv(SceneEffectEnvironment *oldEnvironment) = 0;
48};
49
50class MainSceneEffect : public SceneEffectBase
51{
52 Q_OBJECT
53 QML_NAMED_ELEMENT(MainSceneEffect)
54public:
55 explicit MainSceneEffect(QQuick3DObject *p = nullptr);
56
57private:
58 void registerWithEnv(SceneEffectEnvironment *newEnvironment) override;
59 void unregisterWithEnv(SceneEffectEnvironment *oldEnvironment) override;
60};
61
62class DepthOfFieldEffect : public SceneEffectBase
63{
64 Q_OBJECT
65 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
66 QML_NAMED_ELEMENT(DepthOfFieldEffect)
67public:
68 explicit DepthOfFieldEffect(QQuick3DObject *p = nullptr);
69
70 bool enabled() const;
71 void setEnabled(bool newEnabled);
72
73signals:
74 void enabledChanged();
75
76private:
77 void registerWithEnv(SceneEffectEnvironment *newEnvironment) override;
78 void unregisterWithEnv(SceneEffectEnvironment *oldEnvironment) override;
79 bool m_enabled = false;
80};
81
82class SceneEffectEnvironment : public QQuick3DSceneEnvironment
83{
84 Q_OBJECT
85 QML_NAMED_ELEMENT(SceneEffectEnvironment)
86
87public:
88 explicit SceneEffectEnvironment(QQuick3DObject *p = nullptr);
89 void setMainSceneEffect(MainSceneEffect *tonemapper);
90 void setDeptOfFieldEffect(DepthOfFieldEffect *dof);
91
92protected:
93 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
94
95private:
96 QVector<QQuick3DEffect *> m_effects;
97 MainSceneEffect *m_tonemapper = nullptr;
98 DepthOfFieldEffect *m_dof = nullptr;
99
100protected:
101 const QVector<QQuick3DEffect *> &effectList() const override;
102 bool useBuiltinTonemapper() const override;
103};
104
105QT_END_NAMESPACE
106
107#endif // SCENEEFFECTS_H
108

source code of qtquick3d/src/helpers/impl/sceneeffects_p.h