1// Copyright (C) 2017 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_RENDER_SHADERBUILDER_H
5#define QT3DRENDER_RENDER_SHADERBUILDER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DRender/qshaderprogram.h>
19#include <Qt3DRender/private/backendnode_p.h>
20#include <Qt3DRender/private/qgraphicsapifilter_p.h>
21#include <Qt3DCore/private/vector_helper_p.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace Qt3DRender {
26
27namespace Render {
28
29struct ShaderBuilderUpdate
30{
31 Qt3DCore::QNodeId builderId;
32 Qt3DRender::QShaderProgram::ShaderType shaderType;
33 QByteArray shaderCode;
34};
35
36class Q_3DRENDERSHARED_PRIVATE_EXPORT ShaderBuilder : public BackendNode
37{
38public:
39 static QString getPrototypesFile();
40 static void setPrototypesFile(const QString &file);
41 static QStringList getPrototypeNames();
42
43 ShaderBuilder();
44 ~ShaderBuilder();
45 void cleanup();
46
47 Qt3DCore::QNodeId shaderProgramId() const;
48 QStringList enabledLayers() const;
49
50 GraphicsApiFilterData graphicsApi() const;
51 void setGraphicsApi(const GraphicsApiFilterData &graphicsApi);
52
53 QUrl shaderGraph(QShaderProgram::ShaderType type) const;
54 void setShaderGraph(QShaderProgram::ShaderType type, const QUrl &url);
55
56 QByteArray shaderCode(QShaderProgram::ShaderType type) const;
57 bool isShaderCodeDirty(QShaderProgram::ShaderType type) const;
58
59 void generateCode(QShaderProgram::ShaderType type);
60
61 void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
62
63 std::vector<ShaderBuilderUpdate> takePendingUpdates() { return Qt3DCore::moveAndClear(data&: m_pendingUpdates); }
64
65 QByteArray hashKeyForShaderGraph(QShaderProgram::ShaderType type) const;
66
67private:
68 void setEnabledLayers(const QStringList &layers);
69
70 GraphicsApiFilterData m_graphicsApi;
71 Qt3DCore::QNodeId m_shaderProgramId;
72 QStringList m_enabledLayers;
73 QHash<QShaderProgram::ShaderType, QUrl> m_graphs;
74 QHash<QShaderProgram::ShaderType, QByteArray> m_codes;
75 QSet<QShaderProgram::ShaderType> m_dirtyTypes;
76 std::vector<ShaderBuilderUpdate> m_pendingUpdates;
77};
78
79} // namespace Render
80} // namespace Qt3DRender
81
82QT_END_NAMESPACE
83
84#endif // QT3DRENDER_RENDER_SHADERBUILDER_H
85

source code of qt3d/src/render/materialsystem/shaderbuilder_p.h