diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-06-29 17:53:13 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-07-01 11:36:58 +0000 |
commit | da839643397dda062cf7371e01fc1c990b7cf7c3 (patch) | |
tree | c84bc317ee0aab06e762a5466274787190aa4180 /src/quick/items | |
parent | 023170b8276659118fd28d787597d749f80501e9 (diff) |
Add a core profile file selector to OpenGL ShaderEffect
Similarly to what we do with "hlsl" in the D3D12 backend, we can use
"glslcore" to provide a file-based alternative to the GraphcsInfo or
OpenGLInfo-based conditions in the fragmentShader and vertexShader
properties. This is particularly useful in a few places inside Qt,
for example Quick Controls, that have to cater to all possiblities.
Change-Id: I5d89e7b1534afbc323a663869bab7796bd1a337d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickopenglshadereffect.cpp | 12 | ||||
-rw-r--r-- | src/quick/items/qquickopenglshadereffect_p.h | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp index f65062ae38..b77a7830ff 100644 --- a/src/quick/items/qquickopenglshadereffect.cpp +++ b/src/quick/items/qquickopenglshadereffect.cpp @@ -53,6 +53,7 @@ #include <QtQml/qqmlfile.h> #include <QtCore/qsignalmapper.h> +#include <QtCore/qfileselector.h> QT_BEGIN_NAMESPACE @@ -325,7 +326,16 @@ void QQuickOpenGLShaderEffectCommon::updateShader(QQuickItem *item, Key::ShaderT // A qrc or file URL means the shader source is to be read from the specified file. QUrl srcUrl(QString::fromUtf8(source.sourceCode[shaderType])); if (!srcUrl.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) || srcUrl.isLocalFile()) { - const QString fn = QQmlFile::urlToLocalFileOrQrc(srcUrl); + if (!fileSelector) { + fileSelector = new QFileSelector(item); + // There may not be an OpenGL context accessible here. So rely on + // the window's requestedFormat(). + if (item->window() + && item->window()->requestedFormat().profile() == QSurfaceFormat::CoreProfile) { + fileSelector->setExtraSelectors(QStringList() << QStringLiteral("glslcore")); + } + } + const QString fn = fileSelector->select(QQmlFile::urlToLocalFileOrQrc(srcUrl)); QFile f(fn); if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { source.sourceCode[shaderType] = f.readAll(); diff --git a/src/quick/items/qquickopenglshadereffect_p.h b/src/quick/items/qquickopenglshadereffect_p.h index bc60ba1e83..062eedd744 100644 --- a/src/quick/items/qquickopenglshadereffect_p.h +++ b/src/quick/items/qquickopenglshadereffect_p.h @@ -66,6 +66,7 @@ QT_BEGIN_NAMESPACE class QSGContext; class QSignalMapper; +class QFileSelector; class QQuickOpenGLCustomMaterialShader; // Common class for QQuickOpenGLShaderEffect and QQuickCustomParticle. @@ -74,7 +75,7 @@ struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon typedef QQuickOpenGLShaderEffectMaterialKey Key; typedef QQuickOpenGLShaderEffectMaterial::UniformData UniformData; - QQuickOpenGLShaderEffectCommon(QObject *host) : host(host) { } + QQuickOpenGLShaderEffectCommon(QObject *host) : host(host), fileSelector(nullptr) { } ~QQuickOpenGLShaderEffectCommon(); void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); void connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); @@ -95,6 +96,7 @@ struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon QVector<UniformData> uniformData[Key::ShaderTypeCount]; QVector<QSignalMapper *> signalMappers[Key::ShaderTypeCount]; QString parseLog; + QFileSelector *fileSelector; }; |