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 enum class GlslOption {
34 GlslEsFragDefaultFloatPrecisionMedium = 0x01
35 };
36 Q_DECLARE_FLAGS(GlslOptions, GlslOption)
37
38 QShaderBaker();
39 ~QShaderBaker();
40
41 void setSourceFileName(const QString &fileName);
42 void setSourceFileName(const QString &fileName, QShader::Stage stage);
43
44 void setSourceDevice(QIODevice *device, QShader::Stage stage,
45 const QString &fileName = QString());
46
47 void setSourceString(const QByteArray &sourceString, QShader::Stage stage,
48 const QString &fileName = QString());
49
50 typedef QPair<QShader::Source, QShaderVersion> GeneratedShader;
51 void setGeneratedShaders(const QList<GeneratedShader> &v);
52 void setGeneratedShaderVariants(const QList<QShader::Variant> &v);
53
54 void setPreamble(const QByteArray &preamble);
55 void setBatchableVertexShaderExtraInputLocation(int location);
56 void setPerTargetCompilation(bool enable);
57 void setBreakOnShaderTranslationError(bool enable);
58 void setTessellationMode(QShaderDescription::TessellationMode mode);
59 void setTessellationOutputVertexCount(int count);
60 void setMultiViewCount(int count);
61
62 void setSpirvOptions(SpirvOptions options);
63 void setGlslOptions(GlslOptions options);
64
65 QShader bake();
66
67 QString errorMessage() const;
68
69private:
70 Q_DISABLE_COPY(QShaderBaker)
71 QShaderBakerPrivate *d = nullptr;
72};
73
74Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderBaker::SpirvOptions)
75Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderBaker::GlslOptions)
76
77QT_END_NAMESPACE
78
79#endif
80

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