For Qt Quick to work, a graphics driver that provides Direct 3D 11.1, Vulkan 1.0, or OpenGL 2.1 or higher is required. As of Qt 6, the default for Qt Quick on Windows is Direct3D 11. This is different from Qt 5, where the default was OpenGL, either directly, or through ANGLE, an OpenGL to Direct3D translator. ANGLE is no longer shipped with Qt in Qt 6.
To force using Direct3D's software rasterizer (WARP), set the environment variable
QSG_RHI_PREFER_SOFTWARE_RENDERER
to
1
.
To request using Vulkan or OpenGL, both of which require a Vulkan or OpenGL driver to be installed, set the environment variable
QSG_RHI_BACKEND
to
vulkan
or
opengl
, or use the equivalent
C++ API
in
main()
.
While not the default for Qt Quick , OpenGL is still commonly used in many Qt applications, for example in QWidget -based applications building on QOpenGLWindow or QOpenGLWidget . The following sections cover some OpenGL specifics of a Qt build.
Qt supports choosing and loading the OpenGL implementation at runtime. This mode is the default, and can be explicitly requested by passing
-opengl dynamic
给 configure 脚本。
configure -opengl dynamic
This configuration is the most flexible because no dependencies or assumptions are hardcoded about the OpenGL implementation during build time. It allows robust application deployment. When a given environment fails to provide a proper OpenGL 2.0 implementation, it will fall back automatically to load an alternative to
opengl32.dll
, the default name of which is
opengl32sw.dll
. The pre-built Qt packages ship a build of Mesa llvmpipe, a software rasterizer implementation of OpenGL, under that name.
当配置采用
-opengl dynamic
,不管 Qt 还是应用程序构建使用
qmake
or
CMake
will link to opengl32.lib. Instead, the library is chosen and loaded at runtime. By default, Qt will determine whether the system's opengl32.dll provides OpenGL 2 functions. If these are present, opengl32.dll is used, otherwise it attempts to load
opengl32sw.dll
。详见下文。
可以配置加载机制透过
QT_OPENGL
环境变量和以下应用程序属性:
Qt::AA_UseDesktopOpenGL
相当于设置
QT_OPENGL
to
desktop
.
Qt::AA_UseOpenGLES
Has no effect in Qt 6.
Qt::AA_UseSoftwareOpenGL
相当于设置
QT_OPENGL
to
software
.
当明确请求某个配置时,不会进行任何校验在应用程序启动时,也就是说,将不审查系统提供的 opengl32.dll。
The dynamic loading has a significant impact on applications that contain native OpenGL calls: they may fail to link since opengl32.lib is not automatically specified to the linker. Instead, applications are expected to use the OpenGL functions via the
QOpenGLFunctions
class. Thus the direct dependency on the OpenGL library is removed and all calls will be routed during runtime to the implementation chosen by Qt. Alternatively, applications are free to make direct OpenGL function calls if they add opengl32.lib to their .pro project files:
LIBS += opengl32.lib
(Visual Studio) 或
LIBS += -lopengl32
(MinGW). The result is, from the application's perspective, equivalent to the
-opengl desktop
Qt 构建配置。
Qt::AA_UseSoftwareOpenGL
的特殊之处是它会试着采用非标准名称来加载 OpenGL 实现。默认名称为
opengl32sw.dll
。这允许随附仅软件 OpenGL 实现,例如构建
Mesa 采用 llvmpipe
,在此名称下。若有必要,可以覆盖文件名通过设置
QT_OPENGL_DLL
环境变量。
根据图形卡和驱动程序版本,提供 JSON 格式配置文件以指定要使用哪种 OpenGL 实现是可能的。位置的给定通过环境变量
QT_OPENGL_BUGLIST
。相对路径的解析使用
QLibraryInfo::SettingsPath
or
QStandardPaths::ConfigLocation
。文件利用驱动程序 Bug 列表所使用的格式,在
Chromium 工程
。它由条目的列表组成,各条目指定一组条件和特征关键词的列表。通常,使用设备 ID 和供应商 ID 相匹配的特定图形卡。可以找到它们,在输出的
qtdiag6
or
dxdiag
工具。
以下特征关键词与选取 OpenGL 实现相关:
注意:
In Qt 6, the legacy ANGLE related keywords (
disable_angle
,
disable_d3d11
,
disable_d3d9
) are accepted, but have no effect.
disable_desktopgl
- 禁用 OpenGL。这确保 Qt 不会试图使用常规 OpenGL (opengl32.dll),且它会采用 ANGLE 立即开始。这对阻止坏的 OpenGL 驱动程序崩溃应用程序,很有用。
disable_rotation
- Forces the application to run in landscape orientation always. It has no effect when using a software OpenGL implementation. This is intended for drivers that have issues with rotation.
disable_program_cache
- Disable storing shader program binaries on disk.
样本文件看起来像:
{
"entries": [
{
"id": 1,
"description": "Disable D3D11 on older nVidia drivers",
"os": {
"type": "win"
},
"vendor_id": "0x10de",
"device_id": ["0x0DE9"],
"driver_version": {
"op": "<=",
"value": "8.17.12.6973"
},
"features": [
"disable_d3d11"
]
},
...
当
QT_OPENGL_BUGLIST
未指定,将使用内置列表。这通常包括一些较旧的、功能较差图形卡采用
disable_desktopgl
set, in order to prevent Qt from using their unstable desktop OpenGL implementations and instead fall back to attempting to load the software-based alternative library right away.
在实践中,最常见组合期望如下:
disable_desktopgl
- 若系统提供 OpenGL 2.0 或更新版本,但已知驱动程序不稳定且易于崩溃。
disable_desktopgl
, disable_angle - When no accelerated path is desired. This ensures that the only option Qt tries is the software rasterizer (opengl32sw.dll). Can be useful in virtual machines and applications that are deployed on a wide range of old systems.
匹配给定卡 (或驱动程序) 的支持键,如下。注意:其中一些是 Qt 特有的。
os.type
- 操作系统:
win
,
linux
,
macosx
,
android
os.version
- 内核版本
os.release
- 指定 Windows 操作系统发行列表:
xp
,
vista
,
7
,
8
,
8.1
,
10
.
vendor_id
- 来自适配器标识符的供应商
device_id
- PCI 设备 ID 列表。
driver_version
- 来自适配器标识符的驱动程序版本
driver_description
- 匹配,当值是来自适配器标识符的驱动程序所描述的子字符串时
gl_vendor
- 匹配,当值是子字符串对于
GL_VENDOR
string
要禁用所有黑名单,设置环境变量
QT_NO_OPENGL_BUGLIST
为任意值。这会跳过读取任何配置文件,且假定未禁用任何内容,不管是驱动程序还是 OS。
注意:
虽然通常不需要,
QT_NO_OPENGL_BUGLIST
can become relevant in certain virtual environments, with multiple, possibly virtual, graphics adapters present. If the logs from categories like
qt.qpa.gl
indicate that the detection of the driver and display adapter leads to incorrectly disabling OpenGL, it is then recommended to set this environment variable in order to enable the application to run normally. This environment variable was introduced in Qt 5.15.
An alternative to the default
dynamic
OpenGL builds is to depend directly on opengl32.dll. For this mode, pass the command line options
-opengl desktop
给 configure 脚本。
configure -opengl desktop
注意: Using EGL and OpenGL ES is not supported on Windows. In Qt 6, OpenGL on Windows always implies using WGL as the windowing system interface.
In such Qt builds, many Qt shared libraries, and also Qt applications will have a dependency to opengl32.dll, and therefore using an alternative library is not possible.