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
qsgdefaultinternalrectanglenode.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qsgdefaultinternalrectanglenode_p.h"
6
7
#
include
<
QtQuick
/
qsgvertexcolormaterial
.
h
>
8
#
include
<
QtQuick
/
qsgtexturematerial
.
h
>
9
10
#
include
<
QtQuick
/
private
/
qsgcontext_p
.
h
>
11
12
#
include
<
QtCore
/
qmath
.
h
>
13
#
include
<
QtCore
/
qvarlengtharray
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
class
SmoothColorMaterialRhiShader
:
public
QSGMaterialShader
18
{
19
public
:
20
SmoothColorMaterialRhiShader
(
int
viewCount);
21
22
bool
updateUniformData
(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
override
;
23
};
24
25
SmoothColorMaterialRhiShader
::
SmoothColorMaterialRhiShader
(
int
viewCount)
26
{
27
setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/smoothcolor.vert.qsb"
), viewCount);
28
setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/smoothcolor.frag.qsb"
), viewCount);
29
}
30
31
bool
SmoothColorMaterialRhiShader
::
updateUniformData
(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
32
{
33
bool
changed =
false
;
34
QByteArray *buf = state.uniformData();
35
const
int
shaderMatrixCount = newMaterial->viewCount();
36
const
int
matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
37
38
for
(
int
viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
39
if
(state.isMatrixDirty()) {
40
const
QMatrix4x4 m = state.combinedMatrix(viewIndex);
41
memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
42
changed =
true
;
43
}
44
}
45
46
if
(oldMaterial ==
nullptr
) {
47
// The viewport is constant, so set the pixel size uniform only once.
48
const
QRect r = state.viewportRect();
49
const
QVector2D v(2.0f / r.width(), 2.0f / r.height());
50
Q_ASSERT(
sizeof
(v) == 8);
51
memcpy(buf->data() + 64 * shaderMatrixCount, &v, 8);
52
changed =
true
;
53
}
54
55
if
(state.isOpacityDirty()) {
56
const
float
opacity = state.opacity();
57
memcpy(buf->data() + 64 * shaderMatrixCount + 8, &opacity, 4);
58
changed =
true
;
59
}
60
61
return
changed;
62
}
63
64
65
QSGSmoothColorMaterial::QSGSmoothColorMaterial()
66
{
67
setFlag(RequiresFullMatrixExceptTranslate,
true
);
68
setFlag(Blending,
true
);
69
}
70
71
int
QSGSmoothColorMaterial::compare(
const
QSGMaterial *)
const
72
{
73
// all state in vertex attributes -> all smoothcolor materials are equal
74
return
0;
75
}
76
77
QSGMaterialType *QSGSmoothColorMaterial::type()
const
78
{
79
static
QSGMaterialType type;
80
return
&type;
81
}
82
83
QSGMaterialShader *QSGSmoothColorMaterial::createShader(QSGRendererInterface::RenderMode renderMode)
const
84
{
85
Q_UNUSED(renderMode);
86
return
new
SmoothColorMaterialRhiShader(viewCount());
87
}
88
89
QSGDefaultInternalRectangleNode::QSGDefaultInternalRectangleNode()
90
{
91
setMaterial(&m_material);
92
}
93
94
void
QSGDefaultInternalRectangleNode::updateMaterialAntialiasing()
95
{
96
if
(m_antialiasing)
97
setMaterial(&m_smoothMaterial);
98
else
99
setMaterial(&m_material);
100
}
101
102
void
QSGDefaultInternalRectangleNode::updateMaterialBlending(QSGNode::DirtyState *state)
103
{
104
// smoothed material is always blended, so no change in material state
105
if
(material() == &m_material) {
106
bool
wasBlending = (m_material.flags() & QSGMaterial::Blending);
107
bool
isBlending = (m_gradient_stops.size() > 0 && !m_gradient_is_opaque)
108
|| (m_color.alpha() < 255 && m_color.alpha() != 0)
109
|| (m_pen_width > 0 && m_border_color.alpha() < 255);
110
if
(wasBlending != isBlending) {
111
m_material.setFlag(QSGMaterial::Blending, isBlending);
112
*state |= QSGNode::DirtyMaterial;
113
}
114
}
115
}
116
117
QT_END_NAMESPACE
SmoothColorMaterialRhiShader
Definition
qsgdefaultinternalrectanglenode.cpp:18
SmoothColorMaterialRhiShader::updateUniformData
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
Definition
qsgdefaultinternalrectanglenode.cpp:31
SmoothColorMaterialRhiShader::SmoothColorMaterialRhiShader
SmoothColorMaterialRhiShader(int viewCount)
Definition
qsgdefaultinternalrectanglenode.cpp:25
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quick
scenegraph
qsgdefaultinternalrectanglenode.cpp
Generated on
for Qt by
1.18.0