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
qsgdefaultinternalimagenode.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
"qsgdefaultinternalimagenode_p.h"
6
#
include
<
private
/
qsgdefaultrendercontext_p
.
h
>
7
#
include
<
private
/
qsgmaterialshader_p
.
h
>
8
#
include
<
private
/
qsgtexturematerial_p
.
h
>
9
#
include
<
qopenglfunctions
.
h
>
10
#
include
<
QtCore
/
qmath
.
h
>
11
#
include
<
rhi
/
qrhi
.
h
>
12
13
QT_BEGIN_NAMESPACE
14
15
class
SmoothTextureMaterialRhiShader
:
public
QSGTextureMaterialRhiShader
16
{
17
public
:
18
SmoothTextureMaterialRhiShader
(
int
viewCount);
19
20
bool
updateUniformData
(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
override
;
21
};
22
23
24
QSGSmoothTextureMaterial::QSGSmoothTextureMaterial()
25
{
26
setFlag(RequiresFullMatrixExceptTranslate,
true
);
27
setFlag(Blending,
true
);
28
}
29
30
void
QSGSmoothTextureMaterial::setTexture(QSGTexture *texture)
31
{
32
m_texture = texture;
33
}
34
35
QSGMaterialType *QSGSmoothTextureMaterial::type()
const
36
{
37
static
QSGMaterialType type;
38
return
&type;
39
}
40
41
QSGMaterialShader *QSGSmoothTextureMaterial::createShader(QSGRendererInterface::RenderMode renderMode)
const
42
{
43
Q_UNUSED(renderMode);
44
return
new
SmoothTextureMaterialRhiShader(viewCount());
45
}
46
47
SmoothTextureMaterialRhiShader
::
SmoothTextureMaterialRhiShader
(
int
viewCount)
48
:
QSGTextureMaterialRhiShader
(
viewCount
)
49
{
50
setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/smoothtexture.vert.qsb"
), viewCount);
51
setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/smoothtexture.frag.qsb"
), viewCount);
52
}
53
54
bool
SmoothTextureMaterialRhiShader
::
updateUniformData
(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
55
{
56
bool
changed =
false
;
57
QByteArray *buf = state.uniformData();
58
const
int
shaderMatrixCount = newMaterial->viewCount();
59
60
if
(!oldMaterial) {
61
// The viewport is constant, so set the pixel size uniform only once (per batches with the same material).
62
const
QRect r = state.viewportRect();
63
const
QVector2D v(2.0f / r.width(), 2.0f / r.height());
64
// mat4 matrix, float opacity, vec2 pixelSize, and the vec2 must be 2*4 aligned
65
memcpy(buf->data() + 64 * shaderMatrixCount + 8, &v, 8);
66
changed =
true
;
67
}
68
69
changed |= QSGTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
70
71
return
changed;
72
}
73
74
75
QSGDefaultInternalImageNode::QSGDefaultInternalImageNode(QSGDefaultRenderContext *rc)
76
: m_rc(rc)
77
{
78
setMaterial(&m_materialO);
79
setOpaqueMaterial(&m_material);
80
}
81
82
void
QSGDefaultInternalImageNode::setFiltering(QSGTexture::Filtering filtering)
83
{
84
if
(m_material.filtering() == filtering)
85
return
;
86
87
m_material.setFiltering(filtering);
88
m_materialO.setFiltering(filtering);
89
m_smoothMaterial.setFiltering(filtering);
90
markDirty(DirtyMaterial);
91
}
92
93
void
QSGDefaultInternalImageNode::setMipmapFiltering(QSGTexture::Filtering filtering)
94
{
95
if
(m_material.mipmapFiltering() == filtering)
96
return
;
97
98
m_material.setMipmapFiltering(filtering);
99
m_materialO.setMipmapFiltering(filtering);
100
m_smoothMaterial.setMipmapFiltering(filtering);
101
markDirty(DirtyMaterial);
102
}
103
104
void
QSGDefaultInternalImageNode::setVerticalWrapMode(QSGTexture::WrapMode wrapMode)
105
{
106
if
(m_material.verticalWrapMode() == wrapMode)
107
return
;
108
109
m_material.setVerticalWrapMode(wrapMode);
110
m_materialO.setVerticalWrapMode(wrapMode);
111
m_smoothMaterial.setVerticalWrapMode(wrapMode);
112
markDirty(DirtyMaterial);
113
}
114
115
void
QSGDefaultInternalImageNode::setHorizontalWrapMode(QSGTexture::WrapMode wrapMode)
116
{
117
if
(m_material.horizontalWrapMode() == wrapMode)
118
return
;
119
120
m_material.setHorizontalWrapMode(wrapMode);
121
m_materialO.setHorizontalWrapMode(wrapMode);
122
m_smoothMaterial.setHorizontalWrapMode(wrapMode);
123
markDirty(DirtyMaterial);
124
}
125
126
void
QSGDefaultInternalImageNode::updateMaterialAntialiasing()
127
{
128
if
(m_antialiasing) {
129
setMaterial(&m_smoothMaterial);
130
setOpaqueMaterial(
nullptr
);
131
}
else
{
132
setMaterial(&m_materialO);
133
setOpaqueMaterial(&m_material);
134
}
135
}
136
137
void
QSGDefaultInternalImageNode::setMaterialTexture(QSGTexture *texture)
138
{
139
m_material.setTexture(texture);
140
m_materialO.setTexture(texture);
141
m_smoothMaterial.setTexture(texture);
142
}
143
144
QSGTexture *QSGDefaultInternalImageNode::materialTexture()
const
145
{
146
return
m_material.texture();
147
}
148
149
bool
QSGDefaultInternalImageNode::updateMaterialBlending()
150
{
151
const
bool
alpha = m_material.flags() & QSGMaterial::Blending;
152
if
(materialTexture() && alpha != materialTexture()->hasAlphaChannel()) {
153
m_material.setFlag(QSGMaterial::Blending, !alpha);
154
return
true
;
155
}
156
return
false
;
157
}
158
159
inline
static
bool
isPowerOfTwo
(
int
x)
160
{
161
// Assumption: x >= 1
162
return
x == (x & -x);
163
}
164
165
bool
QSGDefaultInternalImageNode::supportsWrap(
const
QSize &size)
const
166
{
167
bool
npotSupported = m_rc->rhi() && m_rc->rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat);
168
return
npotSupported || (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height()));
169
}
170
171
QT_END_NAMESPACE
SmoothTextureMaterialRhiShader
Definition
qsgdefaultinternalimagenode.cpp:16
SmoothTextureMaterialRhiShader::SmoothTextureMaterialRhiShader
SmoothTextureMaterialRhiShader(int viewCount)
Definition
qsgdefaultinternalimagenode.cpp:47
SmoothTextureMaterialRhiShader::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
qsgdefaultinternalimagenode.cpp:54
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
isPowerOfTwo
static bool isPowerOfTwo(int x)
Definition
qsgdefaultinternalimagenode.cpp:159
qtdeclarative
src
quick
scenegraph
qsgdefaultinternalimagenode.cpp
Generated on
for Qt by
1.18.0