-
Bug
-
Resolution: Out of scope
-
P2: Important
-
None
-
5.13.2, 5.15.1
-
None
-
GPU: Intel HD Graphics 530
正如此错误所描述的:QTBUG-55733:具有兼容性配置文件的 Windows 上的 Intel 始终要求 #version
Windows 上具有兼容性配置文件的 Intel GPU 始终需要在第一行 #version。但是我发现对于 opengl 3.0 及更高版本,Windows 上的 Intel GPU 总是需要在第一行有 version,即使是核心配置文件也是如此。
当我在 QML 中使用 DropShadow 并通过 QSurfaceFormat 将 opengl 版本设置为 3.2 时,我发现了这个问题。
QSurfaceFormat format;
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
format.setVersion(3, 3);
format.setProfile(QSurfaceFormat::CoreProfile);
}
QQuickView view;
view.setFormat(format);
软件将提示以下错误消息。
QOpenGLShader::compile(Vertex): ERROR: 0:2: '' : syntax error: #version directive must occur in a shader before anything else
ERROR: 0:2: '' : illegal order of preprocessor directives
并且 DropShadow 的效果与预期不符,而是变成了粉红色的边框。
通过对 Qt 的源代码进行以下修改,并重新编译 Qt。我解决了这个问题。
// qtbase\src\gui\opengl\qopenglshaderprogram.cpp // before bool QOpenGLShader::compileSourceCode(const char *source) { ... // QTBUG-55733: Intel on Windows with Compatibility profile requires a #version always if (ctx->format().profile() == QSurfaceFormat::CompatibilityProfile) { qDebug() << "QTBUG-55733"; const char *vendor = reinterpret_cast<const char *>(ctx->functions()->glGetString(GL_VENDOR)); if (vendor && !strcmp(vendor, "Intel")) { static const char version110[] = "#version 110\n"; sourceChunks.append(version110); sourceChunkLengths.append(GLint(sizeof(version110)) - 1); } } ... } // after, Comment out the place to judge whether it is compatibility profile, so the #version will be always added in the first line even for the core profile bool QOpenGLShader::compileSourceCode(const char *source) { ... // QTBUG-55733: Intel on Windows with Compatibility profile requires a #version always // if (ctx->format().profile() == QSurfaceFormat::CompatibilityProfile) { qDebug() << "QTBUG-55733"; const char *vendor = reinterpret_cast<const char *>(ctx->functions()->glGetString(GL_VENDOR)); if (vendor && !strcmp(vendor, "Intel")) { static const char version110[] = "#version 110\n"; sourceChunks.append(version110); sourceChunkLengths.append(GLint(sizeof(version110)) - 1); } // } ... }
最后,我实现了所需的阴影效果。