1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
// Qt-Security score:critical reason:data-parser
#include "shaderfeatures.h"
#include <QStringList>
#include <QDebug>
ShaderFeatures::ShaderFeatures()
{
}
// Browse the shaders and check which features are used in them.
void ShaderFeatures::update(const QString &vs, const QString &fs, const QString &qml)
{
QStringList vsList = vs.split("\n");
QStringList fsList = fs.split("\n");
QStringList code = vsList + fsList;
Features newFeatures = {};
m_gridMeshWidth = 1;
m_gridMeshHeight = 1;
for (const auto &line : code)
checkLine(line, newFeatures);
// iTime may also be used in QML side, without being used in shaders.
// In this case enable the time helpers creation.
if (qml.contains("iTime"))
newFeatures.setFlag(Time, true);
if (newFeatures != m_enabledFeatures)
m_enabledFeatures = newFeatures;
}
void ShaderFeatures::checkLine(const QString &line, Features &features) {
if (line.contains("iTime"))
features.setFlag(Time, true);
if (line.contains("iFrame"))
features.setFlag(Frame, true);
if (line.contains("iResolution"))
features.setFlag(Resolution, true);
if (line.contains("iSource"))
features.setFlag(Source, true);
if (line.contains("iMouse"))
features.setFlag(Mouse, true);
if (line.contains("fragCoord"))
features.setFlag(FragCoord, true);
if (line.contains("@mesh")) {
// Get the mesh size, remove "@mesh"
QString l = line.trimmed().sliced(5);
QStringList list = l.split(QLatin1Char(','));
if (list.size() >= 2) {
int w = list.at(0).trimmed().toInt();
int h = list.at(1).trimmed().toInt();
// Set size to max values
m_gridMeshWidth = std::max(m_gridMeshWidth, w);
m_gridMeshHeight = std::max(m_gridMeshHeight, h);
}
// If is bigger than default (1, 1), set the feature
if (m_gridMeshWidth > 1 || m_gridMeshHeight > 1)
features.setFlag(GridMesh, true);
}
if (line.contains("@blursources"))
features.setFlag(BlurSources, true);
}
|