| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSSGRENDERHELPERS_H |
| 5 | #define QSSGRENDERHELPERS_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is part of the QtQuick3D API, with limited compatibility guarantees. |
| 12 | // Usage of this API may make your code source and binary incompatible with |
| 13 | // future versions of Qt. |
| 14 | // |
| 15 | |
| 16 | #include <QtQuick3DRuntimeRender/qtquick3druntimerenderglobal.h> |
| 17 | |
| 18 | #include <ssg/qssgrenderbasetypes.h> |
| 19 | |
| 20 | #include <QtCore/qsize.h> |
| 21 | |
| 22 | #include <QtGui/qmatrix4x4.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QSSGFrameData; |
| 27 | class QRhiRenderPassDescriptor; |
| 28 | class QRhiTexture; |
| 29 | class QSSGRhiGraphicsPipelineState; |
| 30 | class QSSGRenderContextInterface; |
| 31 | class QSSGRenderExtension; |
| 32 | |
| 33 | #ifdef Q_QDOC |
| 34 | typedef quint64 QSSGPrepContextId; |
| 35 | typedef quint64 QSSGPrepResultId; |
| 36 | typedef quint64 QSSGRenderablesId; |
| 37 | #else |
| 38 | enum class QSSGPrepContextId : quint64 { Invalid }; |
| 39 | enum class QSSGPrepResultId : quint64 { Invalid }; |
| 40 | enum class QSSGRenderablesId : quint64 { Invalid }; |
| 41 | #endif |
| 42 | |
| 43 | enum class QSSGRenderablesFilter : quint32 |
| 44 | { |
| 45 | Opaque = 0x1, |
| 46 | Transparent = 0x2, |
| 47 | All = Opaque | Transparent |
| 48 | }; |
| 49 | |
| 50 | Q_DECLARE_FLAGS(QSSGRenderablesFilters, QSSGRenderablesFilter) |
| 51 | |
| 52 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGModelHelpers |
| 53 | { |
| 54 | public: |
| 55 | using MaterialList = QList<QSSGResourceId>; |
| 56 | |
| 57 | static void setModelMaterials(const QSSGFrameData &frameData, |
| 58 | QSSGRenderablesId renderablesId, |
| 59 | QSSGNodeId model, |
| 60 | MaterialList materials); |
| 61 | |
| 62 | static void setModelMaterials(const QSSGFrameData &frameData, |
| 63 | QSSGRenderablesId renderablesId, |
| 64 | MaterialList materials); |
| 65 | |
| 66 | [[nodiscard]] static QMatrix4x4 getGlobalTransform(const QSSGFrameData &frameData, |
| 67 | QSSGNodeId model, |
| 68 | QSSGPrepContextId prepId = {}); |
| 69 | |
| 70 | [[nodiscard]] static QMatrix4x4 getLocalTransform(const QSSGFrameData &frameData, |
| 71 | QSSGNodeId model); |
| 72 | [[nodiscard]] static float getGlobalOpacity(const QSSGFrameData &frameData, |
| 73 | QSSGNodeId model); |
| 74 | [[nodiscard]] static float getGlobalOpacity(const QSSGFrameData &frameData, |
| 75 | QSSGNodeId model, |
| 76 | QSSGPrepContextId prepId); |
| 77 | [[nodiscard]] static float getLocalOpacity(const QSSGFrameData &frameData, |
| 78 | QSSGNodeId model); |
| 79 | |
| 80 | static void setGlobalTransform(const QSSGFrameData &frameData, |
| 81 | QSSGRenderablesId prepId, |
| 82 | QSSGNodeId model, |
| 83 | const QMatrix4x4 &transform); |
| 84 | |
| 85 | static void setGlobalOpacity(const QSSGFrameData &frameData, |
| 86 | QSSGRenderablesId renderablesId, |
| 87 | QSSGNodeId model, |
| 88 | float opacity); |
| 89 | private: |
| 90 | QSSGModelHelpers(); |
| 91 | }; |
| 92 | |
| 93 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGCameraHelpers |
| 94 | { |
| 95 | public: |
| 96 | static QMatrix4x4 getViewProjectionMatrix(const QSSGCameraId cameraId, |
| 97 | const QMatrix4x4 *globalTransform = nullptr); |
| 98 | |
| 99 | private: |
| 100 | QSSGCameraHelpers(); |
| 101 | }; |
| 102 | |
| 103 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderHelpers |
| 104 | { |
| 105 | public: |
| 106 | using NodeList = QList<QSSGNodeId>; |
| 107 | |
| 108 | enum class CreateFlag : quint32 |
| 109 | { |
| 110 | None, |
| 111 | Recurse = 0x1, |
| 112 | Steal = 0x2 |
| 113 | }; |
| 114 | |
| 115 | Q_DECLARE_FLAGS(CreateFlags, CreateFlag) |
| 116 | |
| 117 | [[nodiscard]] static QSSGRenderablesId createRenderables(const QSSGFrameData &frameData, |
| 118 | QSSGPrepContextId prepId, |
| 119 | const NodeList &nodes, |
| 120 | CreateFlags flags = CreateFlag::None); |
| 121 | |
| 122 | [[nodiscard]] static QSSGPrepContextId prepareForRender(const QSSGFrameData &frameData, |
| 123 | const QSSGRenderExtension &ext, |
| 124 | QSSGCameraId cameraId, |
| 125 | quint32 slot = 0); |
| 126 | |
| 127 | [[nodiscard]] static QSSGPrepResultId commit(const QSSGFrameData &frameData, |
| 128 | QSSGPrepContextId prepId, |
| 129 | QSSGRenderablesId renderablesId, |
| 130 | float lodThreshold = 1.0f); |
| 131 | |
| 132 | static void prepareRenderables(const QSSGFrameData &frameData, |
| 133 | QSSGPrepResultId prepId, |
| 134 | QRhiRenderPassDescriptor *renderPassDescriptor, |
| 135 | QSSGRhiGraphicsPipelineState &ps, |
| 136 | QSSGRenderablesFilters filter = QSSGRenderablesFilter::All); |
| 137 | |
| 138 | static void renderRenderables(const QSSGFrameData &frameData, |
| 139 | QSSGPrepResultId prepId); |
| 140 | |
| 141 | |
| 142 | private: |
| 143 | QSSGRenderHelpers(); |
| 144 | }; |
| 145 | |
| 146 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderExtensionHelpers |
| 147 | { |
| 148 | public: |
| 149 | static void registerRenderResult(const QSSGFrameData &frameData, |
| 150 | QSSGExtensionId extension, |
| 151 | QRhiTexture *texture); |
| 152 | |
| 153 | private: |
| 154 | QSSGRenderExtensionHelpers(); |
| 155 | }; |
| 156 | |
| 157 | QT_END_NAMESPACE |
| 158 | |
| 159 | #endif // QSSGRENDERHELPERS_H |
| 160 | |