aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/effectcomposer/shaderfeatures.cpp
diff options
context:
space:
mode:
authorMahmoud Badri <[email protected]>2024-01-26 14:55:50 +0200
committerMahmoud Badri <[email protected]>2024-01-26 13:36:18 +0000
commit33bbab25b6ad42d6d786cb04f72bc1947b594b99 (patch)
tree785a8974f43f1214a001ff96100d4d4186d27c4b /src/plugins/effectcomposer/shaderfeatures.cpp
parent5c7090c90e2d310a1bd0f3b1564a7a0a97d0a721 (diff)
QmlDesigner: Rename effect maker plugin files to effect composer
Change-Id: I1d09c1088b4067a479f2e7cc396a348f1b48614f Reviewed-by: Miikka Heikkinen <[email protected]>
Diffstat (limited to 'src/plugins/effectcomposer/shaderfeatures.cpp')
-rw-r--r--src/plugins/effectcomposer/shaderfeatures.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/plugins/effectcomposer/shaderfeatures.cpp b/src/plugins/effectcomposer/shaderfeatures.cpp
new file mode 100644
index 00000000000..5690db5f174
--- /dev/null
+++ b/src/plugins/effectcomposer/shaderfeatures.cpp
@@ -0,0 +1,91 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "shaderfeatures.h"
+#include <QStringList>
+#include <QDebug>
+
+namespace EffectComposer {
+
+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");
+
+ const QStringList code = vsList + fsList;
+ Features newFeatures = {};
+ m_gridMeshWidth = 1;
+ m_gridMeshHeight = 1;
+ for (const QString &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;
+}
+
+bool ShaderFeatures::enabled(ShaderFeatures::Feature feature) const
+{
+ return m_enabledFeatures.testFlag(feature);
+}
+
+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);
+}
+
+int ShaderFeatures::gridMeshHeight() const
+{
+ return m_gridMeshHeight;
+}
+
+int ShaderFeatures::gridMeshWidth() const
+{
+ return m_gridMeshWidth;
+}
+
+} // namespace EffectComposer
+