File indexing completed on 2024-05-05 16:16:43

0001 /*
0002  * This file is part of KQuickCharts
0003  * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 #ifndef LINECHARTMATERIAL_H
0009 #define LINECHARTMATERIAL_H
0010 
0011 #include <QColor>
0012 #include <QSGMaterial>
0013 #include <QSGMaterialShader>
0014 
0015 #include "SDFShader.h"
0016 
0017 class LineChartMaterial : public QSGMaterial
0018 {
0019 public:
0020     LineChartMaterial();
0021     ~LineChartMaterial();
0022 
0023     QSGMaterialType *type() const override;
0024 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0025     QSGMaterialShader *createShader() const override;
0026 #else
0027     QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override;
0028 #endif
0029     int compare(const QSGMaterial *other) const override;
0030 
0031     float aspect = 1.0;
0032     float lineWidth = 0.0;
0033     float smoothing = 0.1;
0034 };
0035 
0036 class LineChartShader : public SDFShader
0037 {
0038 public:
0039     LineChartShader();
0040     ~LineChartShader();
0041 
0042 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0043     char const *const *attributeNames() const override;
0044 
0045     void initialize() override;
0046     void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
0047 
0048 private:
0049     int m_matrixLocation = 0;
0050     int m_opacityLocation = 0;
0051     int m_lineWidthLocation = 0;
0052     int m_aspectLocation = 0;
0053     int m_smoothingLocation = 0;
0054 #else
0055     bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
0056 #endif
0057 };
0058 
0059 #endif // LINECHARTMATERIAL_H