1/*
2 * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#include "BarChartMaterial.h"
8
9BarChartMaterial::BarChartMaterial()
10{
11 setFlag(flags: QSGMaterial::Blending);
12}
13
14BarChartMaterial::~BarChartMaterial()
15{
16}
17
18QSGMaterialType *BarChartMaterial::type() const
19{
20 static QSGMaterialType type;
21 return &type;
22}
23
24QSGMaterialShader *BarChartMaterial::createShader(QSGRendererInterface::RenderMode) const
25{
26 return new BarChartShader();
27}
28
29int BarChartMaterial::compare(const QSGMaterial *other) const
30{
31 auto material = static_cast<const BarChartMaterial *>(other);
32
33 /* clang-format off */
34 if (material->aspect == aspect
35 && qFuzzyCompare(p1: material->radius, p2: radius)
36 && material->backgroundColor == backgroundColor) { /* clang-format on */
37 return 0;
38 }
39
40 return QSGMaterial::compare(other);
41}
42
43BarChartShader::BarChartShader()
44{
45 setShaders(QStringLiteral("barchart.vert"), QStringLiteral("barchart.frag"));
46}
47
48BarChartShader::~BarChartShader()
49{
50}
51
52bool BarChartShader::updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
53{
54 bool changed = false;
55
56 UniformDataStream uniformData(state);
57
58 if (state.isMatrixDirty()) {
59 uniformData << state.combinedMatrix();
60 changed = true;
61 } else {
62 uniformData.skip<QMatrix4x4>();
63 }
64
65 if (state.isOpacityDirty()) {
66 uniformData << state.opacity();
67 changed = true;
68 } else {
69 uniformData.skip<float>();
70 }
71
72 if (!oldMaterial || newMaterial->compare(other: oldMaterial) != 0) {
73 const auto material = static_cast<BarChartMaterial *>(newMaterial);
74 uniformData << material->aspect;
75 uniformData << material->radius;
76 uniformData << material->backgroundColor;
77 changed = true;
78 }
79
80 return changed;
81}
82

source code of kquickcharts/src/scenegraph/BarChartMaterial.cpp