| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSSG_RENDER_REFLECTION_MAP_H |
| 5 | #define QSSG_RENDER_REFLECTION_MAP_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 <QtQuick3DRuntimeRender/private/qtquick3druntimerenderglobal_p.h> |
| 19 | #include <QtQuick3DRuntimeRender/private/qssgrenderreflectionprobe_p.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class QRhi; |
| 24 | class QRhiCommandBuffer; |
| 25 | class QSSGRhiContext; |
| 26 | class QSSGRenderContextInterface; |
| 27 | |
| 28 | class QRhiRenderBuffer; |
| 29 | class QRhiTextureRenderTarget; |
| 30 | class QRhiRenderPassDescriptor; |
| 31 | class QRhiTexture; |
| 32 | class QRhiGraphicsPipeline; |
| 33 | class QRhiShaderResourceBindings; |
| 34 | class QRhiBuffer; |
| 35 | |
| 36 | struct QSSGReflectionMapEntry |
| 37 | { |
| 38 | QSSGReflectionMapEntry(); |
| 39 | |
| 40 | static QSSGReflectionMapEntry withRhiTexturedCubeMap(quint32 probeIdx, |
| 41 | QRhiTexture *preFiltered); |
| 42 | static QSSGReflectionMapEntry withRhiCubeMap(quint32 probeIdx, |
| 43 | QRhiTexture *cube, |
| 44 | QRhiTexture *prefiltered, |
| 45 | QRhiRenderBuffer *depthStencil); |
| 46 | |
| 47 | void renderMips(QSSGRhiContext *rhiCtx); |
| 48 | void destroyRhiResources(); |
| 49 | |
| 50 | quint32 m_probeIndex; |
| 51 | |
| 52 | // RHI resources |
| 53 | QRhiTexture *m_rhiCube = nullptr; |
| 54 | QRhiTexture *m_rhiPrefilteredCube = nullptr; |
| 55 | QRhiRenderBuffer *m_rhiDepthStencil = nullptr; |
| 56 | QVarLengthArray<QRhiTextureRenderTarget *, 6> m_rhiRenderTargets; |
| 57 | QRhiRenderPassDescriptor *m_rhiRenderPassDesc = nullptr; |
| 58 | |
| 59 | QRhiGraphicsPipeline *m_prefilterPipeline = nullptr; |
| 60 | QRhiGraphicsPipeline *m_irradiancePipeline = nullptr; |
| 61 | QRhiShaderResourceBindings *m_prefilterSrb = nullptr; |
| 62 | QRhiShaderResourceBindings *m_irradianceSrb = nullptr; |
| 63 | QRhiBuffer *m_prefilterVertBuffer = nullptr; |
| 64 | QRhiBuffer *m_prefilterFragBuffer = nullptr; |
| 65 | QRhiBuffer *m_irradianceFragBuffer = nullptr; |
| 66 | QMap<int, QVarLengthArray<QRhiTextureRenderTarget *, 6>> m_rhiPrefilterRenderTargetsMap; |
| 67 | QRhiRenderPassDescriptor *m_rhiPrefilterRenderPassDesc = nullptr; |
| 68 | QMap<int, QSize> m_prefilterMipLevelSizes; |
| 69 | |
| 70 | QVarLengthArray<QRhiShaderResourceBindings *, 6> m_skyBoxSrbs; |
| 71 | |
| 72 | QMatrix4x4 m_viewProjection; |
| 73 | |
| 74 | bool m_needsRender = false; |
| 75 | bool m_rendered = false; |
| 76 | |
| 77 | QSSGRenderReflectionProbe::ReflectionTimeSlicing m_timeSlicing = QSSGRenderReflectionProbe::ReflectionTimeSlicing::None; |
| 78 | int m_timeSliceFrame = 1; |
| 79 | QSSGRenderTextureCubeFace m_timeSliceFace = { QSSGRenderTextureCubeFaces[0] }; |
| 80 | Q_QUICK3D_PROFILE_ID |
| 81 | }; |
| 82 | |
| 83 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderReflectionMap |
| 84 | { |
| 85 | typedef QVector<QSSGReflectionMapEntry> TReflectionMapEntryList; |
| 86 | Q_DISABLE_COPY(QSSGRenderReflectionMap) |
| 87 | |
| 88 | public: |
| 89 | const QSSGRenderContextInterface &m_context; |
| 90 | |
| 91 | explicit QSSGRenderReflectionMap(const QSSGRenderContextInterface &inContext); |
| 92 | ~QSSGRenderReflectionMap(); |
| 93 | void releaseCachedResources(); |
| 94 | |
| 95 | void addReflectionMapEntry(qint32 probeIdx, const QSSGRenderReflectionProbe &probe); |
| 96 | void addTexturedReflectionMapEntry(qint32 probeIdx, const QSSGRenderReflectionProbe &probe); |
| 97 | |
| 98 | QSSGReflectionMapEntry *reflectionMapEntry(int probeIdx); |
| 99 | |
| 100 | qint32 reflectionMapEntryCount() { return m_reflectionMapList.size(); } |
| 101 | |
| 102 | private: |
| 103 | TReflectionMapEntryList m_reflectionMapList; |
| 104 | }; |
| 105 | |
| 106 | using QSSGRenderReflectionMapPtr = std::shared_ptr<QSSGRenderReflectionMap>; |
| 107 | |
| 108 | QT_END_NAMESPACE |
| 109 | |
| 110 | #endif |
| 111 | |