Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dcustommaterial_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGCUSTOMMATERIAL_H
5#define QSSGCUSTOMMATERIAL_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 <QtQuick3D/private/qquick3dmaterial_p.h>
19#include <QtCore/qurl.h>
20
21#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
23#include <QtQuick3D/private/qquick3dshaderutils_p.h>
24
26
27class Q_QUICK3D_EXPORT QQuick3DCustomMaterial : public QQuick3DMaterial
28{
30 Q_PROPERTY(ShadingMode shadingMode READ shadingMode WRITE setShadingMode NOTIFY shadingModeChanged)
31 Q_PROPERTY(QUrl fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
32 Q_PROPERTY(QUrl vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
33 Q_PROPERTY(BlendMode sourceBlend READ srcBlend WRITE setSrcBlend NOTIFY srcBlendChanged)
34 Q_PROPERTY(BlendMode destinationBlend READ dstBlend WRITE setDstBlend NOTIFY dstBlendChanged)
35 Q_PROPERTY(BlendMode sourceAlphaBlend READ srcAlphaBlend WRITE setSrcAlphaBlend NOTIFY srcAlphaBlendChanged REVISION(6, 7))
36 Q_PROPERTY(BlendMode destinationAlphaBlend READ dstAlphaBlend WRITE setDstAlphaBlend NOTIFY dstAlphaBlendChanged REVISION(6, 7))
37 Q_PROPERTY(bool alwaysDirty READ alwaysDirty WRITE setAlwaysDirty NOTIFY alwaysDirtyChanged)
38 Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth NOTIFY lineWidthChanged)
39
40 QML_NAMED_ELEMENT(CustomMaterial)
41
42public:
43 enum class ShadingMode
44 {
45 Unshaded,
46 Shaded
47 };
48 Q_ENUM(ShadingMode)
49
50 enum class BlendMode
51 {
52 NoBlend,
53 Zero,
54 One,
55 SrcColor,
56 OneMinusSrcColor,
57 DstColor,
58 OneMinusDstColor,
59 SrcAlpha,
60 OneMinusSrcAlpha,
61 DstAlpha,
62 OneMinusDstAlpha,
63 ConstantColor,
64 OneMinusConstantColor,
65 ConstantAlpha,
66 OneMinusConstantAlpha,
67 SrcAlphaSaturate
68 };
69 Q_ENUM(BlendMode)
70
71 explicit QQuick3DCustomMaterial(QQuick3DObject *parent = nullptr);
72 ~QQuick3DCustomMaterial() override;
73
74 ShadingMode shadingMode() const;
75 QUrl vertexShader() const;
76 QUrl fragmentShader() const;
77 BlendMode srcBlend() const;
78 BlendMode dstBlend() const;
79 Q_REVISION(6, 7) BlendMode srcAlphaBlend() const;
80 Q_REVISION(6, 7) BlendMode dstAlphaBlend() const;
81 bool alwaysDirty() const;
82 float lineWidth() const;
83
84public Q_SLOTS:
85 void setShadingMode(QQuick3DCustomMaterial::ShadingMode mode);
86 void setVertexShader(const QUrl &url);
87 void setFragmentShader(const QUrl &url);
88 void setSrcBlend(QQuick3DCustomMaterial::BlendMode mode);
89 void setDstBlend(QQuick3DCustomMaterial::BlendMode mode);
90 Q_REVISION(6, 7) void setSrcAlphaBlend(QQuick3DCustomMaterial::BlendMode mode);
91 Q_REVISION(6, 7) void setDstAlphaBlend(QQuick3DCustomMaterial::BlendMode mode);
92 void setAlwaysDirty(bool alwaysDirty);
93 void setLineWidth(float width);
94
96 void shadingModeChanged();
97 void vertexShaderChanged();
98 void fragmentShaderChanged();
99 void srcBlendChanged();
100 void dstBlendChanged();
101 Q_REVISION(6, 7) void srcAlphaBlendChanged();
102 Q_REVISION(6, 7) void dstAlphaBlendChanged();
103 void alwaysDirtyChanged();
104 void lineWidthChanged();
105
106protected:
107 enum Dirty : quint32 {
108 TextureDirty = 0x1,
109 PropertyDirty = 0x2,
110 ShaderSettingsDirty = 0x4,
111 DynamicPropertiesDirty = 0x8, // Special case for custom materials created manually
112 AllDirty = std::numeric_limits<quint32>::max() ^ DynamicPropertiesDirty // (DynamicPropertiesDirty is intentionally excluded from AllDirty)
113 };
114
115 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
116 void itemChange(ItemChange, const ItemChangeData &) override;
117 void markAllDirty() override;
118 static void markDirty(QQuick3DCustomMaterial &that, QQuick3DCustomMaterial::Dirty type);
119
120private Q_SLOTS:
121 void onPropertyDirty();
122 void onTextureDirty();
123
124private:
126 friend class QQuick3DViewport;
127
128 void setDynamicTextureMap(QQuick3DShaderUtilsTextureInput *textureMap);
129
130 QSet<QQuick3DShaderUtilsTextureInput *> m_dynamicTextureMaps;
131 quint32 m_dirtyAttributes = Dirty::AllDirty;
132 BlendMode m_srcBlend = BlendMode::NoBlend;
133 BlendMode m_dstBlend = BlendMode::NoBlend;
134 BlendMode m_srcAlphaBlend = BlendMode::NoBlend;
135 BlendMode m_dstAlphaBlend = BlendMode::NoBlend;
136 ShadingMode m_shadingMode = ShadingMode::Shaded;
137 QUrl m_vertexShader;
138 QUrl m_fragmentShader;
139 bool m_alwaysDirty = false;
140 float m_lineWidth = 1.0f;
141};
142
144
145#endif // QSSGCUSTOMMATERIAL_H
Q_REVISION(6, 7) BlendMode srcAlphaBlend() const
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
@ One
GLenum mode
GLint GLsizei width
GLenum type
#define QML_NAMED_ELEMENT(NAME)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_SLOTS
#define Q_SIGNALS
unsigned int quint32
Definition qtypes.h:50
QUrl url("example.com")
[constructor-url-reference]
label setLineWidth(2)