summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopenglshaderprogram.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/opengl/qopenglshaderprogram.cpp')
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp98
1 files changed, 54 insertions, 44 deletions
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index a7c8aae989..cd582c5285 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -337,9 +337,10 @@ bool QOpenGLShaderPrivate::compile(QOpenGLShader *q)
// Dump the source code if we got it
if (sourceCodeBuffer) {
- qWarning("*** Problematic %s shader source code ***", type);
- qWarning() << qPrintable(QString::fromLatin1(sourceCodeBuffer));
- qWarning("***");
+ qWarning("*** Problematic %s shader source code ***\n"
+ "%ls\n"
+ "***",
+ type, qUtf16Printable(QString::fromLatin1(sourceCodeBuffer)));
}
// Cleanup
@@ -431,73 +432,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);
}
/*!
@@ -1225,8 +1237,7 @@ int QOpenGLShaderProgram::attributeLocation(const char *name) const
if (d->linked && d->programGuard && d->programGuard->id()) {
return d->glfuncs->glGetAttribLocation(d->programGuard->id(), name);
} else {
- qWarning() << "QOpenGLShaderProgram::attributeLocation(" << name
- << "): shader program is not linked";
+ qWarning("QOpenGLShaderProgram::attributeLocation(%s): shader program is not linked", name);
return -1;
}
}
@@ -1489,7 +1500,7 @@ void QOpenGLShaderProgram::setAttributeValue
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
if (rows < 1 || rows > 4) {
- qWarning() << "QOpenGLShaderProgram::setAttributeValue: rows" << rows << "not supported";
+ qWarning("QOpenGLShaderProgram::setAttributeValue: rows %d not supported", rows);
return;
}
if (location != -1) {
@@ -1901,8 +1912,7 @@ int QOpenGLShaderProgram::uniformLocation(const char *name) const
if (d->linked && d->programGuard && d->programGuard->id()) {
return d->glfuncs->glGetUniformLocation(d->programGuard->id(), name);
} else {
- qWarning() << "QOpenGLShaderProgram::uniformLocation(" << name
- << "): shader program is not linked";
+ qWarning("QOpenGLShaderProgram::uniformLocation(%s): shader program is not linked", name);
return -1;
}
}
@@ -2829,7 +2839,7 @@ void QOpenGLShaderProgram::setUniformValueArray(int location, const GLfloat *val
else if (tupleSize == 4)
d->glfuncs->glUniform4fv(location, count, values);
else
- qWarning() << "QOpenGLShaderProgram::setUniformValue: size" << tupleSize << "not supported";
+ qWarning("QOpenGLShaderProgram::setUniformValue: size %d not supported", tupleSize);
}
}