1 | /* |
---|---|
2 | * This file is part of KQuickCharts |
3 | * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> |
4 | * |
5 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #include "LineChartMaterial.h" |
9 | |
10 | LineChartMaterial::LineChartMaterial() |
11 | { |
12 | setFlag(flags: QSGMaterial::Blending); |
13 | } |
14 | |
15 | LineChartMaterial::~LineChartMaterial() |
16 | { |
17 | } |
18 | |
19 | QSGMaterialType *LineChartMaterial::type() const |
20 | { |
21 | static QSGMaterialType type; |
22 | return &type; |
23 | } |
24 | |
25 | QSGMaterialShader *LineChartMaterial::createShader(QSGRendererInterface::RenderMode) const |
26 | { |
27 | return new LineChartShader(); |
28 | } |
29 | |
30 | int LineChartMaterial::compare(const QSGMaterial *other) const |
31 | { |
32 | auto material = static_cast<const LineChartMaterial *>(other); |
33 | |
34 | /* clang-format off */ |
35 | if (qFuzzyCompare(p1: material->aspect, p2: aspect) |
36 | && qFuzzyCompare(p1: material->lineWidth, p2: lineWidth) |
37 | && qFuzzyCompare(p1: material->smoothing, p2: smoothing)) { /* clang-format on */ |
38 | return 0; |
39 | } |
40 | |
41 | return QSGMaterial::compare(other); |
42 | } |
43 | |
44 | LineChartShader::LineChartShader() |
45 | { |
46 | setShaders(QStringLiteral("linechart.vert"), QStringLiteral( "linechart.frag")); |
47 | } |
48 | |
49 | LineChartShader::~LineChartShader() |
50 | { |
51 | } |
52 | |
53 | bool LineChartShader::updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) |
54 | { |
55 | bool changed = false; |
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<LineChartMaterial *>(newMaterial); |
74 | uniformData << material->lineWidth; |
75 | uniformData << material->aspect; |
76 | uniformData << material->smoothing; |
77 | changed = true; |
78 | } |
79 | |
80 | return changed; |
81 | } |
82 |