Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgvertexcolormaterial.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
5
7
9{
10public:
12
13 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
14};
15
17{
18 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/vertexcolor.vert.qsb"), viewCount);
19 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/vertexcolor.frag.qsb"), viewCount);
20}
21
22bool QSGVertexColorMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *)
23{
24 bool changed = false;
25 QByteArray *buf = state.uniformData();
26 const int shaderMatrixCount = newMaterial->viewCount();
27 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
28
29 for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
30 if (state.isMatrixDirty()) {
31 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
32 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
33 changed = true;
34 }
35 }
36
37 if (state.isOpacityDirty()) {
38 const float opacity = state.opacity();
39 memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4);
40 changed = true;
41 }
42
43 return changed;
44}
45
46
47/*!
48 \class QSGVertexColorMaterial
49 \brief The QSGVertexColorMaterial class provides a convenient way of rendering per-vertex
50 colored geometry in the scene graph.
51
52 \inmodule QtQuick
53 \ingroup qtquick-scenegraph-materials
54
55 \warning This utility class is only functional when running with the
56 default backend of the Qt Quick scenegraph.
57
58 The vertex color material will give each vertex in a geometry a color. Pixels between
59 vertices will be linearly interpolated. The colors can contain transparency.
60
61 The geometry to be rendered with vertex color must have the following layout. Attribute
62 position 0 must contain vertices. Attribute position 1 must contain colors, a tuple of
63 4 values with RGBA layout. Both floats in the range of 0 to 1 and unsigned bytes in
64 the range 0 to 255 are valid for the color values.
65
66 \note The rendering pipeline expects pixels with premultiplied alpha.
67
68 QSGGeometry::defaultAttributes_ColoredPoint2D() can be used to construct an attribute
69 set that is compatible with this material.
70
71 The vertex color material respects both current opacity and current matrix when
72 updating it's rendering state.
73 */
74
75
76/*!
77 Creates a new vertex color material.
78 */
79
80QSGVertexColorMaterial::QSGVertexColorMaterial()
81{
82 setFlag(Blending, true);
83}
84
85
86/*!
87 int QSGVertexColorMaterial::compare() const
88
89 As the vertex color material has all its state in the vertex attributes,
90 all materials will be equal.
91
92 \internal
93 */
94
95int QSGVertexColorMaterial::compare(const QSGMaterial * /* other */) const
96{
97 return 0;
98}
99
100/*!
101 \internal
102 */
103
104QSGMaterialType *QSGVertexColorMaterial::type() const
105{
106 static QSGMaterialType type;
107 return &type;
108}
109
110
111
112/*!
113 \internal
114 */
115
116QSGMaterialShader *QSGVertexColorMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
117{
118 Q_UNUSED(renderMode);
119 return new QSGVertexColorMaterialRhiShader(viewCount());
120}
121
122QT_END_NAMESPACE
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...