1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Gui module |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #ifndef QSHADER_P_H |
38 | #define QSHADER_P_H |
39 | |
40 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists for the convenience |
45 | // of a number of Qt sources files. This header file may change from |
46 | // version to version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | // |
50 | |
51 | #include <QtGui/qtguiglobal.h> |
52 | #include <private/qshaderdescription_p.h> |
53 | |
54 | QT_BEGIN_NAMESPACE |
55 | |
56 | struct QShaderPrivate; |
57 | class QShaderKey; |
58 | |
59 | class Q_GUI_EXPORT QShaderVersion |
60 | { |
61 | public: |
62 | enum Flag { |
63 | GlslEs = 0x01 |
64 | }; |
65 | Q_DECLARE_FLAGS(Flags, Flag) |
66 | |
67 | QShaderVersion() = default; |
68 | QShaderVersion(int v, Flags f = Flags()); |
69 | |
70 | int version() const { return m_version; } |
71 | void setVersion(int v) { m_version = v; } |
72 | |
73 | Flags flags() const { return m_flags; } |
74 | void setFlags(Flags f) { m_flags = f; } |
75 | |
76 | private: |
77 | int m_version = 100; |
78 | Flags m_flags; |
79 | }; |
80 | |
81 | Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderVersion::Flags) |
82 | Q_DECLARE_TYPEINFO(QShaderVersion, Q_MOVABLE_TYPE); |
83 | |
84 | class QShaderCode; |
85 | Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t = 0) noexcept; |
86 | |
87 | class Q_GUI_EXPORT QShaderCode |
88 | { |
89 | public: |
90 | QShaderCode() = default; |
91 | QShaderCode(const QByteArray &code, const QByteArray &entry = QByteArray()); |
92 | |
93 | QByteArray shader() const { return m_shader; } |
94 | void setShader(const QByteArray &code) { m_shader = code; } |
95 | |
96 | QByteArray entryPoint() const { return m_entryPoint; } |
97 | void setEntryPoint(const QByteArray &entry) { m_entryPoint = entry; } |
98 | |
99 | private: |
100 | friend Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t) noexcept; |
101 | |
102 | QByteArray m_shader; |
103 | QByteArray m_entryPoint; |
104 | }; |
105 | |
106 | Q_DECLARE_TYPEINFO(QShaderCode, Q_MOVABLE_TYPE); |
107 | |
108 | class Q_GUI_EXPORT QShader |
109 | { |
110 | public: |
111 | enum Stage { |
112 | VertexStage = 0, |
113 | TessellationControlStage, |
114 | TessellationEvaluationStage, |
115 | GeometryStage, |
116 | FragmentStage, |
117 | ComputeStage |
118 | }; |
119 | |
120 | enum Source { |
121 | SpirvShader = 0, |
122 | GlslShader, |
123 | HlslShader, |
124 | DxbcShader, // fxc |
125 | MslShader, |
126 | DxilShader, // dxc |
127 | MetalLibShader // xcrun metal + xcrun metallib |
128 | }; |
129 | |
130 | enum Variant { |
131 | StandardShader = 0, |
132 | BatchableVertexShader |
133 | }; |
134 | |
135 | QShader(); |
136 | QShader(const QShader &other); |
137 | QShader &operator=(const QShader &other); |
138 | ~QShader(); |
139 | void detach(); |
140 | |
141 | bool isValid() const; |
142 | |
143 | Stage stage() const; |
144 | void setStage(Stage stage); |
145 | |
146 | QShaderDescription description() const; |
147 | void setDescription(const QShaderDescription &desc); |
148 | |
149 | QList<QShaderKey> availableShaders() const; |
150 | QShaderCode shader(const QShaderKey &key) const; |
151 | void setShader(const QShaderKey &key, const QShaderCode &shader); |
152 | void removeShader(const QShaderKey &key); |
153 | |
154 | QByteArray serialized() const; |
155 | static QShader fromSerialized(const QByteArray &data); |
156 | |
157 | using NativeResourceBindingMap = QHash<int, QPair<int, int> >; // binding -> native_binding[, native_binding] |
158 | const NativeResourceBindingMap *nativeResourceBindingMap(const QShaderKey &key) const; |
159 | void setResourceBindingMap(const QShaderKey &key, const NativeResourceBindingMap &map); |
160 | void removeResourceBindingMap(const QShaderKey &key); |
161 | |
162 | private: |
163 | QShaderPrivate *d; |
164 | friend struct QShaderPrivate; |
165 | friend Q_GUI_EXPORT bool operator==(const QShader &, const QShader &) noexcept; |
166 | friend Q_GUI_EXPORT size_t qHash(const QShader &, size_t) noexcept; |
167 | #ifndef QT_NO_DEBUG_STREAM |
168 | friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &); |
169 | #endif |
170 | }; |
171 | |
172 | class Q_GUI_EXPORT QShaderKey |
173 | { |
174 | public: |
175 | QShaderKey() = default; |
176 | QShaderKey(QShader::Source s, |
177 | const QShaderVersion &sver, |
178 | QShader::Variant svar = QShader::StandardShader); |
179 | |
180 | QShader::Source source() const { return m_source; } |
181 | void setSource(QShader::Source s) { m_source = s; } |
182 | |
183 | QShaderVersion sourceVersion() const { return m_sourceVersion; } |
184 | void setSourceVersion(const QShaderVersion &sver) { m_sourceVersion = sver; } |
185 | |
186 | QShader::Variant sourceVariant() const { return m_sourceVariant; } |
187 | void setSourceVariant(QShader::Variant svar) { m_sourceVariant = svar; } |
188 | |
189 | private: |
190 | QShader::Source m_source = QShader::SpirvShader; |
191 | QShaderVersion m_sourceVersion; |
192 | QShader::Variant m_sourceVariant = QShader::StandardShader; |
193 | }; |
194 | |
195 | Q_DECLARE_TYPEINFO(QShaderKey, Q_MOVABLE_TYPE); |
196 | |
197 | Q_GUI_EXPORT bool operator==(const QShader &lhs, const QShader &rhs) noexcept; |
198 | Q_GUI_EXPORT size_t qHash(const QShader &s, size_t seed = 0) noexcept; |
199 | |
200 | inline bool operator!=(const QShader &lhs, const QShader &rhs) noexcept |
201 | { |
202 | return !(lhs == rhs); |
203 | } |
204 | |
205 | Q_GUI_EXPORT bool operator==(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept; |
206 | Q_GUI_EXPORT bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept; |
207 | Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept; |
208 | |
209 | inline bool operator!=(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept |
210 | { |
211 | return !(lhs == rhs); |
212 | } |
213 | |
214 | inline bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs) noexcept |
215 | { |
216 | return !(lhs == rhs); |
217 | } |
218 | |
219 | inline bool operator!=(const QShaderCode &lhs, const QShaderCode &rhs) noexcept |
220 | { |
221 | return !(lhs == rhs); |
222 | } |
223 | |
224 | Q_GUI_EXPORT size_t qHash(const QShaderKey &k, size_t seed = 0) noexcept; |
225 | |
226 | #ifndef QT_NO_DEBUG_STREAM |
227 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &); |
228 | Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderKey &k); |
229 | Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderVersion &v); |
230 | #endif |
231 | |
232 | QT_END_NAMESPACE |
233 | |
234 | #endif |
235 | |