2023-06-29 15:06:11 +03:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-08-30 13:43:24 +03:00
|
|
|
#include "shaderfeatures.h"
|
|
|
|
|
|
2023-08-17 13:41:27 +03:00
|
|
|
#include <QMap>
|
2023-06-29 15:06:11 +03:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2023-08-17 13:41:27 +03:00
|
|
|
class CompositionNode;
|
2023-08-30 13:43:24 +03:00
|
|
|
class Uniform;
|
2023-08-17 13:41:27 +03:00
|
|
|
|
2023-09-01 10:59:02 +03:00
|
|
|
struct EffectError {
|
|
|
|
|
Q_GADGET
|
|
|
|
|
Q_PROPERTY(QString message MEMBER m_message)
|
|
|
|
|
Q_PROPERTY(int line MEMBER m_line)
|
|
|
|
|
Q_PROPERTY(int type MEMBER m_type)
|
2023-09-01 16:43:56 +03:00
|
|
|
|
2023-09-01 10:59:02 +03:00
|
|
|
public:
|
|
|
|
|
QString m_message;
|
|
|
|
|
int m_line = -1;
|
|
|
|
|
int m_type = -1;
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-29 15:06:11 +03:00
|
|
|
class EffectMakerModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
|
|
|
|
|
Q_PROPERTY(int selectedIndex MEMBER m_selectedIndex NOTIFY selectedIndexChanged)
|
2023-09-01 16:43:56 +03:00
|
|
|
Q_PROPERTY(bool shadersUpToDate READ shadersUpToDate WRITE setShadersUpToDate NOTIFY shadersUpToDateChanged)
|
2023-06-29 15:06:11 +03:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
EffectMakerModel(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
|
|
bool isEmpty() const { return m_isEmpty; }
|
|
|
|
|
|
2023-08-17 13:41:27 +03:00
|
|
|
void addNode(const QString &nodeQenPath);
|
2023-06-29 15:06:11 +03:00
|
|
|
|
2023-08-29 16:24:43 +03:00
|
|
|
Q_INVOKABLE void removeNode(int idx);
|
2023-06-29 15:06:11 +03:00
|
|
|
|
2023-09-01 16:43:56 +03:00
|
|
|
bool shadersUpToDate() const;
|
|
|
|
|
void setShadersUpToDate(bool newShadersUpToDate);
|
|
|
|
|
|
2023-06-29 15:06:11 +03:00
|
|
|
signals:
|
|
|
|
|
void isEmptyChanged();
|
|
|
|
|
void selectedIndexChanged(int idx);
|
2023-09-01 10:59:02 +03:00
|
|
|
void effectErrorChanged();
|
2023-09-01 16:43:56 +03:00
|
|
|
void shadersUpToDateChanged();
|
2023-06-29 15:06:11 +03:00
|
|
|
|
|
|
|
|
private:
|
2023-08-17 13:41:27 +03:00
|
|
|
enum Roles {
|
|
|
|
|
NameRole = Qt::UserRole + 1,
|
2023-08-21 11:52:11 +03:00
|
|
|
UniformsRole
|
2023-08-17 13:41:27 +03:00
|
|
|
};
|
|
|
|
|
|
2023-09-01 16:43:56 +03:00
|
|
|
enum ErrorTypes {
|
|
|
|
|
ErrorCommon = -1,
|
|
|
|
|
ErrorQMLParsing,
|
|
|
|
|
ErrorVert,
|
|
|
|
|
ErrorFrag,
|
|
|
|
|
ErrorQMLRuntime,
|
|
|
|
|
ErrorPreprocessor
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-29 15:06:11 +03:00
|
|
|
bool isValidIndex(int idx) const;
|
|
|
|
|
|
2023-08-30 13:43:24 +03:00
|
|
|
const QList<Uniform *> allUniforms();
|
|
|
|
|
|
|
|
|
|
const QString getBufUniform();
|
|
|
|
|
const QString getVSUniforms();
|
|
|
|
|
const QString getFSUniforms();
|
|
|
|
|
|
2023-09-01 10:59:02 +03:00
|
|
|
QString detectErrorMessage(const QString &errorMessage);
|
|
|
|
|
EffectError effectError() const;
|
2023-09-04 14:56:30 +03:00
|
|
|
void setEffectError(const QString &errorMessage, int type = -1, int lineNumber = -1);
|
2023-09-01 10:59:02 +03:00
|
|
|
void resetEffectError(int type);
|
|
|
|
|
|
2023-09-04 13:09:34 +03:00
|
|
|
QString valueAsVariable(const Uniform &uniform);
|
2023-09-01 16:43:56 +03:00
|
|
|
const QString getConstVariables();
|
2023-09-04 14:56:30 +03:00
|
|
|
const QString getDefineProperties();
|
2023-09-01 16:43:56 +03:00
|
|
|
int getTagIndex(const QStringList &code, const QString &tag);
|
|
|
|
|
QString processVertexRootLine(const QString &line);
|
|
|
|
|
QString processFragmentRootLine(const QString &line);
|
|
|
|
|
QStringList getDefaultRootVertexShader();
|
|
|
|
|
QStringList getDefaultRootFragmentShader();
|
|
|
|
|
QStringList removeTagsFromCode(const QStringList &codeLines);
|
|
|
|
|
QString removeTagsFromCode(const QString &code);
|
|
|
|
|
QString getCustomShaderVaryings(bool outState);
|
|
|
|
|
QString generateVertexShader(bool includeUniforms = true);
|
|
|
|
|
QString generateFragmentShader(bool includeUniforms = true);
|
|
|
|
|
void bakeShaders();
|
|
|
|
|
|
2023-08-29 16:24:43 +03:00
|
|
|
QList<CompositionNode *> m_nodes;
|
2023-06-29 15:06:11 +03:00
|
|
|
|
|
|
|
|
int m_selectedIndex = -1;
|
|
|
|
|
bool m_isEmpty = true;
|
2023-09-01 16:43:56 +03:00
|
|
|
// True when shaders haven't changed since last baking
|
|
|
|
|
bool m_shadersUpToDate = true;
|
2023-09-01 10:59:02 +03:00
|
|
|
QMap<int, EffectError> m_effectErrors;
|
2023-08-30 13:43:24 +03:00
|
|
|
ShaderFeatures m_shaderFeatures;
|
2023-09-01 16:43:56 +03:00
|
|
|
QStringList m_shaderVaryingVariables;
|
|
|
|
|
QString m_fragmentShader;
|
|
|
|
|
QString m_vertexShader;
|
2023-06-29 15:06:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|