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/private/qtquick3druntimerenderexports_p.h>
25#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
26#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
27
28QT_BEGIN_NAMESPACE
29
30struct QSSGRenderImage;
31struct QSSGShaderMaterialAdapter;
32class QQuick3DShaderUtilsTextureInput;
33class QQuick3DTexture;
34
35struct 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 QQuick3DTexture *lastConnectedTexture = nullptr;
52 QMetaObject::Connection minFilterChangedConn;
53 QMetaObject::Connection magFilterChangedConn;
54 QMetaObject::Connection mipFilterChangedConn;
55 QMetaObject::Connection horizontalTilingChangedConn;
56 QMetaObject::Connection verticalTilingChangedConn;
57 };
58 using TexturePropertyList = QList<TextureProperty>;
59
60 struct Property
61 {
62 Property() = default;
63 Property(const QByteArray &name, const QVariant &value, QSSGRenderShaderValue::Type shaderDataType, int pid = -1)
64 : name(name), value(value), shaderDataType(shaderDataType), pid(pid)
65 { }
66 QByteArray name;
67 QVariant value;
68 QSSGRenderShaderValue::Type shaderDataType;
69 int pid;
70 };
71 using PropertyList = QList<Property>;
72
73 enum class Flags : quint8
74 {
75 Dirty = 0x1,
76 AlwaysDirty = 0x2
77 };
78 using FlagT = std::underlying_type_t<Flags>;
79
80 enum class ShadingMode // must match QQuick3DCustomMaterial::ShadingMode
81 {
82 Unshaded,
83 Shaded
84 };
85
86 enum class CustomShaderPresenceFlag {
87 Vertex = 1 << 0,
88 Fragment = 1 << 1
89 };
90 Q_DECLARE_FLAGS(CustomShaderPresence, CustomShaderPresenceFlag)
91
92 enum class RenderFlag {
93 Blending = 1 << 0,
94 ScreenTexture = 1 << 1,
95 DepthTexture = 1 << 2,
96 AoTexture = 1 << 3,
97 OverridesPosition = 1 << 4,
98 ProjectionMatrix = 1 << 5,
99 InverseProjectionMatrix = 1 << 6,
100 ScreenMipTexture = 1 << 7,
101 VarColor = 1 << 8,
102 IblOrientation = 1 << 9,
103 Lightmap = 1 << 10,
104 Skinning = 1 << 11,
105 Morphing = 1 << 12
106 };
107 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
108
109 QByteArray m_shaderPathKey;
110 CustomShaderPresence m_customShaderPresence;
111
112 TexturePropertyList m_textureProperties;
113 PropertyList m_properties;
114
115 QSSGRenderImage *m_iblProbe = nullptr;
116 QSSGRenderImage *m_emissiveMap = nullptr;
117 QSSGCullFaceMode m_cullMode = QSSGCullFaceMode::Back;
118 QSSGDepthDrawMode m_depthDrawMode = QSSGDepthDrawMode::OpaqueOnly;
119 RenderFlags m_renderFlags;
120 QRhiGraphicsPipeline::BlendFactor m_srcBlend;
121 QRhiGraphicsPipeline::BlendFactor m_dstBlend;
122 float m_lineWidth = 1.0f;
123
124 QSSGRenderGraphObject *m_nextSibling = nullptr;
125
126 ShadingMode m_shadingMode = ShadingMode::Shaded;
127
128 FlagT m_flags { FlagT(Flags::Dirty) };
129 bool incompleteBuildTimeObject = false; // Used by the shadergen tool
130 bool m_usesSharedVariables = false;
131
132 void markDirty();
133 void clearDirty();
134 void setAlwaysDirty(bool v);
135 [[nodiscard]] inline bool isDirty() const { return ((m_flags & (FlagT(Flags::Dirty) | FlagT(Flags::AlwaysDirty))) != 0); }
136
137 QSSGShaderMaterialAdapter *adapter = nullptr;
138
139 QString debugObjectName;
140};
141
142
143
144Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRenderCustomMaterial::CustomShaderPresence)
145
146QT_END_NAMESPACE
147
148#endif
149

source code of qtquick3d/src/runtimerender/graphobjects/qssgrendercustommaterial_p.h