From 56749925c3bf2973681a4f99a970fcfdb0d0f891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sat, 8 Feb 2025 16:38:33 -0500 Subject: [PATCH] isf: improve include mechanism --- .../3rdparty/libisf/src/isf.cpp | 1 + .../score-plugin-gfx/Gfx/ShaderProgram.cpp | 91 ++++++++++++++++++- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp b/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp index d57a0e6aae..ca7804e7fe 100644 --- a/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp +++ b/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp @@ -92,6 +92,7 @@ float PROGRESS = isf_process_uniforms.PROGRESS; int PASSINDEX = isf_process_uniforms.PASSINDEX; int FRAMEINDEX = isf_process_uniforms.FRAMEINDEX; vec2 RENDERSIZE = isf_process_uniforms.RENDERSIZE; +vec4 MOUSE = isf_process_uniforms.MOUSE; vec4 DATE = isf_process_uniforms.DATE; )_"; diff --git a/src/plugins/score-plugin-gfx/Gfx/ShaderProgram.cpp b/src/plugins/score-plugin-gfx/Gfx/ShaderProgram.cpp index a267fe5224..5e2088d305 100644 --- a/src/plugins/score-plugin-gfx/Gfx/ShaderProgram.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/ShaderProgram.cpp @@ -155,13 +155,99 @@ static std::optional resolveFile_brackets( return std::nullopt; } +static void removeIncludesInComments(QByteArray& data) +{ + static constexpr uint8_t MARKER = 1; + // very basic implementation as there does not seem to be any easily integratable one + if(data.size() < 2) + return; + bool in_long_comment = false; + bool in_line_comment = false; + bool in_string = false; + auto pos = data.begin(); + while(pos < data.end() - 2) + { + if(in_long_comment) + { + if(*pos == '#') + *pos = ' '; + + if(*pos == '*' && *(pos + 1) == '/') + { + // *pos = MARKER; + pos++; + // *pos = MARKER; + in_long_comment = false; + } + else + { + // *pos = MARKER; + } + } + else if(in_line_comment) + { + if(*pos == '#') + *pos = ' '; + + if(*pos == '\n') + { + in_line_comment = false; + } + else + { + // *pos = MARKER; + } + } + else if(in_string) + { + // could happen in string though but well + if(*pos == '"') + { + int num_backslashes_before = 0; + auto p = pos - 1; + while(p >= data.begin() && *p == '\\') + num_backslashes_before++; + + if(num_backslashes_before % 2 == 0) + in_string = false; + } + } + else + { + if(*pos == '/') + { + if(*(pos + 1) == '*') + { + in_long_comment = true; + // *pos = MARKER; + pos++; + // *pos = MARKER; + } + else if(*(pos + 1) == '/') + { + in_line_comment = true; + // *pos = MARKER; + pos++; + // *pos = MARKER; + } + } + else if(*pos == '"') + in_string = true; + } + + pos++; + } +} + static bool resolveGLSLIncludes( QByteArray& data, const QStringList& includes, QString rootPath, int iterations) { + removeIncludesInComments(data); + iterations++; - if(iterations > 30) + if(iterations > 1000) { - qDebug() << "More than 30 iterations, shader include loop likely. Stopping."; + qDebug() << "More than 1000 iterations, shader include loop likely. Stopping."; return false; } int idx = data.indexOf("#include"); @@ -206,7 +292,6 @@ static bool resolveGLSLIncludes( return resolveGLSLIncludes(data, includes, rootPath, iterations); } - } ProgramCache& ProgramCache::instance() noexcept