summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopenglshaderprogram.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-11-17 14:15:53 +0100
committerLiang Qi <liang.qi@qt.io>2016-11-17 14:43:26 +0100
commite5ac4afbf954a3e1616ce8543d46ddc668d0374f (patch)
treebe6d97001edebd5cb74c64aaf0010f3cc76a7293 /src/gui/opengl/qopenglshaderprogram.cpp
parente3ed95dd44b95b6e9361b562807e711d7ce5a58b (diff)
parent03c1a6ac717e3c5693653a5e294214056bda970e (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: mkspecs/features/mac/default_post.prf mkspecs/features/uikit/default_post.prf Change-Id: I2a6f783451f2ac9eb4c1a050f605435d2dacf218
Diffstat (limited to 'src/gui/opengl/qopenglshaderprogram.cpp')
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp81
1 files changed, 46 insertions, 35 deletions
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index 1ed5f7317a..b92d97c143 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -493,73 +493,84 @@ static QVersionDirectivePosition findVersionDirectivePosition(const char *source
{
Q_ASSERT(source);
- QString working = QString::fromUtf8(source);
-
// According to the GLSL spec the #version directive must not be
// preceded by anything but whitespace and comments.
// In order to not get confused by #version directives within a
- // multiline comment, we need to run a minimal preprocessor first.
+ // multiline comment, we need to do some minimal comment parsing
+ // while searching for the directive.
enum {
Normal,
+ StartOfLine,
+ PreprocessorDirective,
CommentStarting,
MultiLineComment,
SingleLineComment,
CommentEnding
- } state = Normal;
+ } state = StartOfLine;
- for (QChar *c = working.begin(); c != working.end(); ++c) {
+ const char *c = source;
+ while (*c) {
switch (state) {
+ case PreprocessorDirective:
+ if (*c == ' ' || *c == '\t')
+ break;
+ if (!strncmp(c, "version", strlen("version"))) {
+ // Found version directive
+ c += strlen("version");
+ while (*c && *c != '\n')
+ ++c;
+ int splitPosition = c - source + 1;
+ int linePosition = int(std::count(source, c, '\n')) + 1;
+ return QVersionDirectivePosition(splitPosition, linePosition);
+ } else if (*c == '/')
+ state = CommentStarting;
+ else if (*c == '\n')
+ state = StartOfLine;
+ else
+ state = Normal;
+ break;
+ case StartOfLine:
+ if (*c == ' ' || *c == '\t')
+ break;
+ else if (*c == '#') {
+ state = PreprocessorDirective;
+ break;
+ }
+ state = Normal;
+ // fall through
case Normal:
- if (*c == QLatin1Char('/'))
+ if (*c == '/')
state = CommentStarting;
+ else if (*c == '\n')
+ state = StartOfLine;
break;
case CommentStarting:
- if (*c == QLatin1Char('*'))
+ if (*c == '*')
state = MultiLineComment;
- else if (*c == QLatin1Char('/'))
+ else if (*c == '/')
state = SingleLineComment;
else
state = Normal;
break;
case MultiLineComment:
- if (*c == QLatin1Char('*'))
+ if (*c == '*')
state = CommentEnding;
- else if (*c == QLatin1Char('#'))
- *c = QLatin1Char('_');
break;
case SingleLineComment:
- if (*c == QLatin1Char('\n'))
+ if (*c == '\n')
state = Normal;
- else if (*c == QLatin1Char('#'))
- *c = QLatin1Char('_');
break;
case CommentEnding:
- if (*c == QLatin1Char('/')) {
+ if (*c == '/')
state = Normal;
- } else {
- if (*c == QLatin1Char('#'))
- *c = QLatin1Char('_');
- if (*c != QLatin1Char('*'))
- state = MultiLineComment;
- }
+ else if (*c != QLatin1Char('*'))
+ state = MultiLineComment;
break;
}
+ ++c;
}
- // Search for #version directive
- int splitPosition = 0;
- int linePosition = 1;
-
- static const QRegularExpression pattern(QStringLiteral("^\\s*#\\s*version.*(\\n)?"),
- QRegularExpression::MultilineOption
- | QRegularExpression::OptimizeOnFirstUsageOption);
- QRegularExpressionMatch match = pattern.match(working);
- if (match.hasMatch()) {
- splitPosition = match.capturedEnd();
- linePosition += int(std::count(working.begin(), working.begin() + splitPosition, QLatin1Char('\n')));
- }
-
- return QVersionDirectivePosition(splitPosition, linePosition);
+ return QVersionDirectivePosition(0, 1);
}
/*!