| 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_CUSTOM_MATERIAL_H |
| 6 | #define QSSG_RENDER_CUSTOM_MATERIAL_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 <QtCore/qurl.h> |
| 20 | #include <QtCore/qvariant.h> |
| 21 | #include <QtCore/qvector.h> |
| 22 | #include <rhi/qrhi.h> |
| 23 | |
| 24 | #include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h> |
| 25 | #include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h> |
| 26 | #include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | struct QSSGRenderImage; |
| 31 | struct QSSGShaderMaterialAdapter; |
| 32 | class QQuick3DShaderUtilsTextureInput; |
| 33 | class QQuick3DTexture; |
| 34 | |
| 35 | struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderCustomMaterial : public QSSGRenderGraphObject |
| 36 | { |
| 37 | QSSGRenderCustomMaterial(); |
| 38 | ~QSSGRenderCustomMaterial(); |
| 39 | |
| 40 | struct TextureProperty |
| 41 | { |
| 42 | QQuick3DShaderUtilsTextureInput *texInput = nullptr; |
| 43 | QSSGRenderImage *texImage = nullptr; |
| 44 | QByteArray name; |
| 45 | QSSGRenderShaderValue::Type shaderDataType; |
| 46 | QSSGRenderTextureFilterOp minFilterType = QSSGRenderTextureFilterOp::Linear; |
| 47 | QSSGRenderTextureFilterOp magFilterType = QSSGRenderTextureFilterOp::Linear; |
| 48 | QSSGRenderTextureFilterOp mipFilterType = QSSGRenderTextureFilterOp::Linear; |
| 49 | QSSGRenderTextureCoordOp horizontalClampType = QSSGRenderTextureCoordOp::ClampToEdge; |
| 50 | QSSGRenderTextureCoordOp verticalClampType = QSSGRenderTextureCoordOp::ClampToEdge; |
| 51 | QSSGRenderTextureCoordOp zClampType = QSSGRenderTextureCoordOp::ClampToEdge; |
| 52 | QQuick3DTexture *lastConnectedTexture = nullptr; |
| 53 | QMetaObject::Connection minFilterChangedConn; |
| 54 | QMetaObject::Connection magFilterChangedConn; |
| 55 | QMetaObject::Connection mipFilterChangedConn; |
| 56 | QMetaObject::Connection horizontalTilingChangedConn; |
| 57 | QMetaObject::Connection verticalTilingChangedConn; |
| 58 | QMetaObject::Connection depthTilingChangedConn; |
| 59 | }; |
| 60 | using TexturePropertyList = QList<TextureProperty>; |
| 61 | |
| 62 | struct Property |
| 63 | { |
| 64 | Property() = default; |
| 65 | Property(const QByteArray &name, const QVariant &value, QSSGRenderShaderValue::Type shaderDataType, int pid = -1) |
| 66 | : name(name), value(value), shaderDataType(shaderDataType), pid(pid) |
| 67 | { } |
| 68 | QByteArray name; |
| 69 | QVariant value; |
| 70 | QSSGRenderShaderValue::Type shaderDataType; |
| 71 | int pid; |
| 72 | }; |
| 73 | using PropertyList = QList<Property>; |
| 74 | |
| 75 | enum class Flags : quint8 |
| 76 | { |
| 77 | Dirty = 0x1, |
| 78 | AlwaysDirty = 0x2 |
| 79 | }; |
| 80 | using FlagT = std::underlying_type_t<Flags>; |
| 81 | |
| 82 | enum class ShadingMode // must match QQuick3DCustomMaterial::ShadingMode |
| 83 | { |
| 84 | Unshaded, |
| 85 | Shaded |
| 86 | }; |
| 87 | |
| 88 | enum class CustomShaderPresenceFlag { |
| 89 | Vertex = 1 << 0, |
| 90 | Fragment = 1 << 1 |
| 91 | }; |
| 92 | Q_DECLARE_FLAGS(CustomShaderPresence, CustomShaderPresenceFlag) |
| 93 | |
| 94 | enum class RenderFlag { |
| 95 | Blending = 1 << 0, |
| 96 | ScreenTexture = 1 << 1, |
| 97 | DepthTexture = 1 << 2, |
| 98 | AoTexture = 1 << 3, |
| 99 | OverridesPosition = 1 << 4, |
| 100 | ProjectionMatrix = 1 << 5, |
| 101 | InverseProjectionMatrix = 1 << 6, |
| 102 | ScreenMipTexture = 1 << 7, |
| 103 | VarColor = 1 << 8, |
| 104 | IblOrientation = 1 << 9, |
| 105 | Lightmap = 1 << 10, |
| 106 | Skinning = 1 << 11, |
| 107 | Morphing = 1 << 12, |
| 108 | ViewIndex = 1 << 13, |
| 109 | Clearcoat = 1 << 14, |
| 110 | ClearcoatFresnelScaleBias = 1 << 15, |
| 111 | FresnelScaleBias = 1 << 16, |
| 112 | Transmission = 1 << 17, |
| 113 | }; |
| 114 | Q_DECLARE_FLAGS(RenderFlags, RenderFlag) |
| 115 | |
| 116 | enum { |
| 117 | RegularShaderPathKeyIndex = 0, |
| 118 | MultiViewShaderPathKeyIndex = 1 |
| 119 | }; |
| 120 | QByteArray m_shaderPathKey[2]; |
| 121 | CustomShaderPresence m_customShaderPresence; |
| 122 | |
| 123 | TexturePropertyList m_textureProperties; |
| 124 | PropertyList m_properties; |
| 125 | |
| 126 | QSSGRenderImage *m_iblProbe = nullptr; |
| 127 | QSSGRenderImage *m_emissiveMap = nullptr; |
| 128 | QSSGCullFaceMode m_cullMode = QSSGCullFaceMode::Back; |
| 129 | QSSGDepthDrawMode m_depthDrawMode = QSSGDepthDrawMode::OpaqueOnly; |
| 130 | RenderFlags m_renderFlags; |
| 131 | QRhiGraphicsPipeline::BlendFactor m_srcBlend; |
| 132 | QRhiGraphicsPipeline::BlendFactor m_dstBlend; |
| 133 | QRhiGraphicsPipeline::BlendFactor m_srcAlphaBlend; |
| 134 | QRhiGraphicsPipeline::BlendFactor m_dstAlphaBlend; |
| 135 | float m_lineWidth = 1.0f; |
| 136 | |
| 137 | QSSGRenderGraphObject *m_nextSibling = nullptr; |
| 138 | |
| 139 | ShadingMode m_shadingMode = ShadingMode::Shaded; |
| 140 | |
| 141 | FlagT m_flags { FlagT(Flags::Dirty) }; |
| 142 | bool incompleteBuildTimeObject = false; // Used by the shadergen tool |
| 143 | bool m_usesSharedVariables = false; |
| 144 | |
| 145 | void markDirty(); |
| 146 | void clearDirty(); |
| 147 | void setAlwaysDirty(bool v); |
| 148 | [[nodiscard]] inline bool isDirty() const { return ((m_flags & (FlagT(Flags::Dirty) | FlagT(Flags::AlwaysDirty))) != 0); } |
| 149 | |
| 150 | QSSGShaderMaterialAdapter *adapter = nullptr; |
| 151 | |
| 152 | QString debugObjectName; |
| 153 | }; |
| 154 | |
| 155 | |
| 156 | |
| 157 | Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderCustomMaterial::CustomShaderPresence) |
| 158 | |
| 159 | QT_END_NAMESPACE |
| 160 | |
| 161 | #endif |
| 162 | |