| 1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QT3DRENDER_QSHADERPROGRAM_H |
| 5 | #define QT3DRENDER_QSHADERPROGRAM_H |
| 6 | |
| 7 | #include <Qt3DCore/qnode.h> |
| 8 | #include <Qt3DRender/qt3drender_global.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | namespace Qt3DRender { |
| 13 | |
| 14 | class QShaderProgramPrivate; |
| 15 | |
| 16 | class Q_3DRENDERSHARED_EXPORT QShaderProgram : public Qt3DCore::QNode |
| 17 | { |
| 18 | Q_OBJECT |
| 19 | Q_PROPERTY(QByteArray vertexShaderCode READ vertexShaderCode WRITE setVertexShaderCode NOTIFY vertexShaderCodeChanged) |
| 20 | Q_PROPERTY(QByteArray tessellationControlShaderCode READ tessellationControlShaderCode WRITE setTessellationControlShaderCode NOTIFY tessellationControlShaderCodeChanged) |
| 21 | Q_PROPERTY(QByteArray tessellationEvaluationShaderCode READ tessellationEvaluationShaderCode WRITE setTessellationEvaluationShaderCode NOTIFY tessellationEvaluationShaderCodeChanged) |
| 22 | Q_PROPERTY(QByteArray geometryShaderCode READ geometryShaderCode WRITE setGeometryShaderCode NOTIFY geometryShaderCodeChanged) |
| 23 | Q_PROPERTY(QByteArray fragmentShaderCode READ fragmentShaderCode WRITE setFragmentShaderCode NOTIFY fragmentShaderCodeChanged) |
| 24 | Q_PROPERTY(QByteArray computeShaderCode READ computeShaderCode WRITE setComputeShaderCode NOTIFY computeShaderCodeChanged) |
| 25 | Q_PROPERTY(QString log READ log NOTIFY logChanged REVISION(2, 9)) |
| 26 | Q_PROPERTY(Status status READ status NOTIFY statusChanged REVISION(2, 9)) |
| 27 | Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged REVISION(2, 15)) |
| 28 | |
| 29 | public: |
| 30 | explicit QShaderProgram(Qt3DCore::QNode *parent = nullptr); |
| 31 | ~QShaderProgram(); |
| 32 | |
| 33 | enum ShaderType { |
| 34 | Vertex = 0, |
| 35 | Fragment, |
| 36 | TessellationControl, |
| 37 | TessellationEvaluation, |
| 38 | Geometry, |
| 39 | Compute |
| 40 | }; |
| 41 | Q_ENUM(ShaderType) // LCOV_EXCL_LINE |
| 42 | |
| 43 | enum Status { |
| 44 | NotReady = 0, |
| 45 | Ready, |
| 46 | Error |
| 47 | }; |
| 48 | Q_ENUM(Status) // LCOV_EXCL_LINE |
| 49 | |
| 50 | enum Format { |
| 51 | GLSL = 0, |
| 52 | SPIRV |
| 53 | }; |
| 54 | Q_ENUM(Format) // LCOV_EXCL_LINE |
| 55 | |
| 56 | // Source code in-line |
| 57 | QByteArray vertexShaderCode() const; |
| 58 | QByteArray tessellationControlShaderCode() const; |
| 59 | QByteArray tessellationEvaluationShaderCode() const; |
| 60 | QByteArray geometryShaderCode() const; |
| 61 | QByteArray fragmentShaderCode() const; |
| 62 | QByteArray computeShaderCode() const; |
| 63 | |
| 64 | void setShaderCode(ShaderType type, const QByteArray &shaderCode); |
| 65 | QByteArray shaderCode(ShaderType type) const; |
| 66 | |
| 67 | QString log() const; |
| 68 | Status status() const; |
| 69 | |
| 70 | void setFormat(Format format); |
| 71 | Format format() const; |
| 72 | |
| 73 | Q_INVOKABLE static QByteArray loadSource(const QUrl &sourceUrl); |
| 74 | |
| 75 | public Q_SLOTS: |
| 76 | void setVertexShaderCode(const QByteArray &vertexShaderCode); |
| 77 | void setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode); |
| 78 | void setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode); |
| 79 | void setGeometryShaderCode(const QByteArray &geometryShaderCode); |
| 80 | void setFragmentShaderCode(const QByteArray &fragmentShaderCode); |
| 81 | void setComputeShaderCode(const QByteArray &computeShaderCode); |
| 82 | |
| 83 | Q_SIGNALS: |
| 84 | void vertexShaderCodeChanged(const QByteArray &vertexShaderCode); |
| 85 | void tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode); |
| 86 | void tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode); |
| 87 | void geometryShaderCodeChanged(const QByteArray &geometryShaderCode); |
| 88 | void fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode); |
| 89 | void computeShaderCodeChanged(const QByteArray &computeShaderCode); |
| 90 | void logChanged(const QString &log); |
| 91 | void statusChanged(Status status); |
| 92 | void formatChanged(Format format); |
| 93 | |
| 94 | protected: |
| 95 | explicit QShaderProgram(QShaderProgramPrivate &dd, Qt3DCore::QNode *parent = nullptr); |
| 96 | |
| 97 | private: |
| 98 | Q_DECLARE_PRIVATE(QShaderProgram) |
| 99 | }; |
| 100 | |
| 101 | } |
| 102 | |
| 103 | QT_END_NAMESPACE |
| 104 | |
| 105 | #endif // QT3DRENDER_QSHADERPROGRAM_H |
| 106 | |