Skip to content

File GradientTexture.hpp

File List > materials > GradientTexture.hpp

Go to the documentation of this file

//
// SPDX-FileCopyrightText: 2026 Michal Grabarczyk
// SPDX-License-Identifier: GPL-3.0-only WITH Universal-FOSS-exception-1.0
//
// This file is also available under a separate commercial license.
// See COMMERCIAL-LICENSING.md for contact information.
//
#pragma once

#include "QAccelPlot/effects/GradientColorTypes.hpp"

#include <QImage>
#include <QSGMaterialShader>

#include <vector>

QT_FORWARD_DECLARE_CLASS(QQuickWindow)
QT_FORWARD_DECLARE_CLASS(QSGTexture)

namespace QAccelPlot {

class GradientTexture {
public:
    GradientTexture() = default;
    ~GradientTexture();

    GradientTexture(const GradientTexture&) = delete;
    GradientTexture& operator=(const GradientTexture&) = delete;

    static const std::vector<GradientStopData>& neutralStops();

    void upload(QQuickWindow* window, const std::vector<GradientStopData>& stops);
    void commit(QSGMaterialShader::RenderState& state, QSGTexture** texture);
    qint64 comparisonKey() const;

private:
    bool matches(const std::vector<GradientStopData>& stops) const;

    QImage image_;
    QSGTexture* texture_{nullptr};
    std::vector<GradientStopData> stops_;
};

} // namespace QAccelPlot