1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
2 | // Copyright (C) 2019 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QSSG_RENDER_SHADOW_MAP_H |
6 | #define QSSG_RENDER_SHADOW_MAP_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtQuick3DRuntimeRender/private/qtquick3druntimerenderglobal_p.h> |
20 | #include <QtGui/QMatrix4x4> |
21 | #include <QtGui/QVector3D> |
22 | #include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QSSGRhiContext; |
27 | class QSSGRenderContextInterface; |
28 | |
29 | class QRhiRenderBuffer; |
30 | class QRhiTextureRenderTarget; |
31 | class QRhiRenderPassDescriptor; |
32 | class QRhiTexture; |
33 | |
34 | enum class ShadowMapModes |
35 | { |
36 | VSM, ///< variance shadow mapping |
37 | CUBE, ///< cubemap omnidirectional shadows |
38 | }; |
39 | |
40 | struct QSSGShadowMapEntry |
41 | { |
42 | QSSGShadowMapEntry(); |
43 | |
44 | static QSSGShadowMapEntry withRhiDepthMap(quint32 lightIdx, |
45 | ShadowMapModes mode, |
46 | QRhiTexture *depthMap, |
47 | QRhiTexture *depthCopy, |
48 | QRhiRenderBuffer *depthStencil); |
49 | |
50 | static QSSGShadowMapEntry withRhiDepthCubeMap(quint32 lightIdx, |
51 | ShadowMapModes mode, |
52 | QRhiTexture *depthCube, |
53 | QRhiTexture *cubeCopy, |
54 | QRhiRenderBuffer *depthStencil); |
55 | |
56 | void destroyRhiResources(); |
57 | |
58 | quint32 m_lightIndex; ///< the light index it belongs to |
59 | ShadowMapModes m_shadowMapMode; ///< shadow map method |
60 | |
61 | // RHI resources |
62 | QRhiTexture *m_rhiDepthMap = nullptr; // shadow map (VSM) |
63 | QRhiTexture *m_rhiDepthCopy = nullptr; // for blur pass (VSM) |
64 | QRhiTexture *m_rhiDepthCube = nullptr; // shadow cube map (CUBE) |
65 | QRhiTexture *m_rhiCubeCopy = nullptr; // for blur pass (CUBE) |
66 | QRhiRenderBuffer *m_rhiDepthStencil = nullptr; // depth/stencil |
67 | QVarLengthArray<QRhiTextureRenderTarget *, 6> m_rhiRenderTargets; // texture RT |
68 | QRhiRenderPassDescriptor *m_rhiRenderPassDesc = nullptr; // texture RT renderpass descriptor |
69 | QRhiTextureRenderTarget *m_rhiBlurRenderTarget0 = nullptr; // texture RT for blur X (targets depthCopy or cubeCopy) |
70 | QRhiTextureRenderTarget *m_rhiBlurRenderTarget1 = nullptr; // texture RT for blur Y (targets depthMap or depthCube) |
71 | QRhiRenderPassDescriptor *m_rhiBlurRenderPassDesc = nullptr; // blur needs its own because no depth/stencil |
72 | |
73 | QMatrix4x4 m_lightVP; ///< light view projection matrix |
74 | QMatrix4x4 m_lightCubeView[6]; ///< light cubemap view matrices |
75 | QMatrix4x4 m_lightView; ///< light view transform |
76 | }; |
77 | |
78 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderShadowMap |
79 | { |
80 | typedef QVector<QSSGShadowMapEntry> TShadowMapEntryList; |
81 | Q_DISABLE_COPY(QSSGRenderShadowMap) |
82 | |
83 | public: |
84 | const QSSGRenderContextInterface &m_context; |
85 | |
86 | explicit QSSGRenderShadowMap(const QSSGRenderContextInterface &inContext); |
87 | ~QSSGRenderShadowMap(); |
88 | void releaseCachedResources(); |
89 | |
90 | void addShadowMapEntry(qint32 lightIdx, |
91 | qint32 width, |
92 | qint32 height, |
93 | ShadowMapModes mode, |
94 | const QString &renderNodeObjName); |
95 | |
96 | QSSGShadowMapEntry *shadowMapEntry(int lightIdx); |
97 | |
98 | qint32 shadowMapEntryCount() { return m_shadowMapList.size(); } |
99 | |
100 | private: |
101 | TShadowMapEntryList m_shadowMapList; |
102 | }; |
103 | |
104 | using QSSGRenderShadowMapPtr = std::shared_ptr<QSSGRenderShadowMap>; |
105 | |
106 | QT_END_NAMESPACE |
107 | |
108 | #endif |
109 | |