1// Copyright (C) 2023 The Qt Company Ltd.
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 QSHADERBAKER_H
5#define QSHADERBAKER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is part of the RHI API, with limited compatibility guarantees.
12// Usage of this API may make your code source and binary incompatible with
13// future versions of Qt.
14//
15
16#include <QtShaderTools/qtshadertoolsglobal.h>
17#include <rhi/qshader.h>
18
19QT_BEGIN_NAMESPACE
20
21struct QShaderBakerPrivate;
22class QIODevice;
23
24class Q_SHADERTOOLS_EXPORT QShaderBaker
25{
26public:
27 enum class SpirvOption {
28 GenerateFullDebugInfo = 0x01,
29 StripDebugAndVarInfo = 0x02
30 };
31 Q_DECLARE_FLAGS(SpirvOptions, SpirvOption)
32
33 QShaderBaker();
34 ~QShaderBaker();
35
36 void setSourceFileName(const QString &fileName);
37 void setSourceFileName(const QString &fileName, QShader::Stage stage);
38
39 void setSourceDevice(QIODevice *device, QShader::Stage stage,
40 const QString &fileName = QString());
41
42 void setSourceString(const QByteArray &sourceString, QShader::Stage stage,
43 const QString &fileName = QString());
44
45 typedef QPair<QShader::Source, QShaderVersion> GeneratedShader;
46 void setGeneratedShaders(const QList<GeneratedShader> &v);
47 void setGeneratedShaderVariants(const QList<QShader::Variant> &v);
48
49 void setPreamble(const QByteArray &preamble);
50 void setBatchableVertexShaderExtraInputLocation(int location);
51 void setPerTargetCompilation(bool enable);
52 void setBreakOnShaderTranslationError(bool enable);
53 void setTessellationMode(QShaderDescription::TessellationMode mode);
54 void setTessellationOutputVertexCount(int count);
55
56 void setSpirvOptions(SpirvOptions options);
57
58 QShader bake();
59
60 QString errorMessage() const;
61
62private:
63 Q_DISABLE_COPY(QShaderBaker)
64 QShaderBakerPrivate *d = nullptr;
65};
66
67Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderBaker::SpirvOptions)
68
69QT_END_NAMESPACE
70
71#endif
72

source code of qtshadertools/src/shadertools/qshaderbaker.h