Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquick3dmaterial.cpp
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
// Qt-Security score:significant reason:default
4
5
6
#
include
"qquick3dmaterial_p.h"
7
#
include
"qquick3dobject_p.h"
8
#
include
"qquick3dscenemanager_p.h"
9
10
#
include
<
QtQuick3DRuntimeRender
/
private
/
qssgrenderdefaultmaterial_p
.
h
>
11
#
include
<
QtQuick3DRuntimeRender
/
private
/
qssgrendercustommaterial_p
.
h
>
12
#
include
<
QtQuick3DUtils
/
private
/
qssgutils_p
.
h
>
13
14
QT_BEGIN_NAMESPACE
15
16
/*!
17
\qmltype Material
18
\inherits Object3D
19
\inqmlmodule QtQuick3D
20
\brief Abstract base type providing functionality common to materials.
21
*/
22
23
/*!
24
\qmlproperty Texture Material::lightProbe
25
26
This property defines a Texture for overriding or setting an image based
27
lighting Texture for use with this material only.
28
29
\note Setting a light probe on the material will override the
30
\l {SceneEnvironment::lightProbe} {scene's light probe} for models using this material.
31
32
\note This property is ignored when Reflection Probe is used to show
33
reflections on the Model using this material because Reflection Probe uses
34
the \l {SceneEnvironment::lightProbe} {scene's light probe}.
35
36
\sa SceneEnvironment::lightProbe
37
*/
38
39
/*!
40
\qmlproperty enumeration Material::cullMode
41
42
This property defines whether primitive culling is enabled, and, when
43
enabled, which primitives are discarded.
44
45
The default value is Material.BackFaceCulling.
46
47
A triangle is considered front-facing if it has a counter-clockwise
48
winding, meaning its vertices in framebuffer coordinates are in
49
counter-clockwise order.
50
51
\value Material.BackFaceCulling Back-facing triangles are discarded.
52
\value Material.FrontFaceCulling Front-facing triangles are discarded.
53
\value Material.NoCulling No triangles are discarded.
54
55
\note Since Qt 6.12 this property also affects picking: a triangle that is
56
discarded when rendering cannot be picked either. With Material.NoCulling
57
both sides of a triangle are pickable.
58
59
\sa {View3D::pick()}{View3D.pick()}
60
*/
61
62
/*!
63
\qmlproperty enumeration Material::depthDrawMode
64
65
This property determines if and when depth rendering takes place for this
66
material. The default behavior when \l {SceneEnvironment::depthTestEnabled}
67
is set to \c true is that during the main render pass only opaque materials
68
will write to the depth buffer. This property makes it possible to change
69
this behavior to fine tune the rendering of a material.
70
71
The default value is Material.OqaqueOnlyDepthDraw
72
73
\value Material.OpaqueOnlyDepthDraw Depth rendering is only performed if
74
the material is opaque.
75
\value Material.AlwaysDepthDraw Depth rendering is always performed
76
regardless of the material type.
77
\value Material.NeverDepthDraw Depth rendering is never performed.
78
\value Material.OpaquePrePassDepthDraw Depth rendering is performed in a
79
separate depth pass, but only opaque values are written. This mode also
80
enables transparent materials to be used in combination with shadows.
81
82
\note If \l {SceneEnvironment::depthPrePassEnabled} is set to \c true then all
83
depth writes will take place as a result of the depth prepass, but it is
84
still necessary to explicitly set \c Material.OpaquePrePassDepthDraw to only
85
write the opaque fragments in the depth and shadow passes.
86
87
*/
88
89
90
QQuick3DMaterial::QQuick3DMaterial(QQuick3DObjectPrivate &dd, QQuick3DObject *parent)
91
: QQuick3DObject(dd, parent) {}
92
93
QQuick3DMaterial::~QQuick3DMaterial()
94
{
95
}
96
97
QQuick3DTexture *QQuick3DMaterial::lightProbe()
const
98
{
99
return
m_iblProbe;
100
}
101
102
QQuick3DMaterial::CullMode QQuick3DMaterial::cullMode()
const
103
{
104
return
m_cullMode;
105
}
106
107
QQuick3DMaterial::DepthDrawMode QQuick3DMaterial::depthDrawMode()
const
108
{
109
return
m_depthDrawMode;
110
}
111
112
void
QQuick3DMaterial::setLightProbe(QQuick3DTexture *iblProbe)
113
{
114
if
(m_iblProbe == iblProbe)
115
return
;
116
117
QQuick3DObjectPrivate::attachWatcher(
this
, &QQuick3DMaterial::setLightProbe, iblProbe, m_iblProbe);
118
119
m_iblProbe = iblProbe;
120
emit lightProbeChanged(m_iblProbe);
121
update();
122
}
123
124
void
QQuick3DMaterial::setCullMode(QQuick3DMaterial::CullMode cullMode)
125
{
126
if
(m_cullMode == cullMode)
127
return
;
128
129
m_cullMode = cullMode;
130
emit cullModeChanged(m_cullMode);
131
update();
132
}
133
134
void
QQuick3DMaterial::setDepthDrawMode(QQuick3DMaterial::DepthDrawMode depthDrawMode)
135
{
136
if
(m_depthDrawMode == depthDrawMode)
137
return
;
138
139
m_depthDrawMode = depthDrawMode;
140
emit depthDrawModeChanged(m_depthDrawMode);
141
update();
142
}
143
144
QSSGRenderGraphObject *QQuick3DMaterial::updateSpatialNode(QSSGRenderGraphObject *node)
145
{
146
if
(!node)
147
return
nullptr
;
148
149
QQuick3DObject::updateSpatialNode(node);
150
151
// Set the common properties
152
if
(node->type == QSSGRenderGraphObject::Type::DefaultMaterial ||
153
node->type == QSSGRenderGraphObject::Type::PrincipledMaterial ||
154
node->type == QSSGRenderGraphObject::Type::SpecularGlossyMaterial) {
155
auto
defaultMaterial =
static_cast
<QSSGRenderDefaultMaterial *>(node);
156
157
if
(!m_iblProbe)
158
defaultMaterial->iblProbe =
nullptr
;
159
else
160
defaultMaterial->iblProbe = m_iblProbe->getRenderImage();
161
162
defaultMaterial->cullMode = QSSGCullFaceMode(m_cullMode);
163
defaultMaterial->depthDrawMode = QSSGDepthDrawMode(m_depthDrawMode);
164
165
DebugViewHelpers::ensureDebugObjectName(defaultMaterial,
this
);
166
167
node = defaultMaterial;
168
}
else
if
(node->type == QSSGRenderGraphObject::Type::CustomMaterial) {
169
auto
customMaterial =
static_cast
<QSSGRenderCustomMaterial *>(node);
170
171
if
(!m_iblProbe)
172
customMaterial->m_iblProbe =
nullptr
;
173
else
174
customMaterial->m_iblProbe = m_iblProbe->getRenderImage();
175
176
customMaterial->m_cullMode = QSSGCullFaceMode(m_cullMode);
177
customMaterial->m_depthDrawMode = QSSGDepthDrawMode(m_depthDrawMode);
178
179
DebugViewHelpers::ensureDebugObjectName(customMaterial,
this
);
180
181
node = customMaterial;
182
}
183
184
return
node;
185
}
186
187
void
QQuick3DMaterial::itemChange(QQuick3DObject::ItemChange change,
const
QQuick3DObject::ItemChangeData &value)
188
{
189
if
(change == QQuick3DObject::ItemSceneChange)
190
updateSceneManager(value.sceneManager);
191
}
192
193
void
QQuick3DMaterial::updateSceneManager(QQuick3DSceneManager *sceneManager)
194
{
195
if
(sceneManager) {
196
QQuick3DObjectPrivate::refSceneManager(m_iblProbe, *sceneManager);
197
}
else
{
198
QQuick3DObjectPrivate::derefSceneManager(m_iblProbe);
199
}
200
}
201
202
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
quick3d
qquick3dmaterial.cpp
Generated on
for Qt by
1.18.0