1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-09 12:32:40 +01:00
ScreenPlay/ScreenPlayShader/shaderlibrary.h

109 lines
2.1 KiB
C
Raw Normal View History

2020-09-10 11:40:07 +02:00
#pragma once
#include <QObject>
#include <QQuickItem>
#include <QString>
#include <memory>
class Shader : public QObject {
Q_OBJECT
Q_PROPERTY(QString vertex READ vertex WRITE setVertex NOTIFY vertexChanged)
Q_PROPERTY(QString fragment READ fragment WRITE setFragment NOTIFY fragmentChanged)
public:
Shader() { }
Shader(const QString& vertex, const QString& fragment)
{
m_vertex = vertex;
m_fragment = fragment;
}
QString vertex() const
{
return m_vertex;
}
QString fragment() const
{
return m_fragment;
}
2020-09-27 16:59:24 +02:00
2020-09-10 11:40:07 +02:00
public slots:
void setVertex(QString vertex)
{
if (m_vertex == vertex)
return;
m_vertex = vertex;
emit vertexChanged(m_vertex);
}
void setFragment(QString fragment)
{
if (m_fragment == fragment)
return;
m_fragment = fragment;
emit fragmentChanged(m_fragment);
}
signals:
void vertexChanged(QString vertex);
void fragmentChanged(QString fragment);
private:
QString m_vertex;
QString m_fragment;
};
class ShaderLibrary : public QQuickItem {
Q_OBJECT
Q_DISABLE_COPY(ShaderLibrary)
Q_PROPERTY(Shader* lightning READ lightning WRITE setLightning NOTIFY lightningChanged)
2020-09-13 19:51:20 +02:00
Q_PROPERTY(Shader* water READ water WRITE setWater NOTIFY waterChanged)
2020-09-10 11:40:07 +02:00
public:
explicit ShaderLibrary(QQuickItem* parent = nullptr);
~ShaderLibrary() override;
Shader* lightning() const
{
return m_lightning.get();
}
2020-09-13 19:51:20 +02:00
Shader* water() const
{
return m_water.get();
}
2020-09-10 11:40:07 +02:00
public slots:
void setLightning(Shader* lightning)
{
if (m_lightning.get() == lightning)
return;
m_lightning.reset(lightning);
emit lightningChanged(m_lightning.get());
}
2020-09-13 19:51:20 +02:00
void setWater(Shader* water)
{
if (m_water.get() == water)
return;
m_water.reset(water);
emit waterChanged(m_water.get());
}
2020-09-10 11:40:07 +02:00
signals:
void lightningChanged(Shader* lightning);
2020-09-13 19:51:20 +02:00
void waterChanged(Shader* water);
2020-09-10 11:40:07 +02:00
private:
std::unique_ptr<Shader> m_lightning;
2020-09-13 19:51:20 +02:00
std::unique_ptr<Shader> m_water;
2020-09-10 11:40:07 +02:00
};