摘要翻译:
此处不做全文翻译,大概意思提取一下,从Qt5.5开始 configure -opengl dynamic作为官方预构建Qt二进制包的默认构建配置,当然也强烈推荐作为自定义构建配置。Qt不会再构建是链接opengl32或 QtANGLE 库,而是在运行时来判断具体加载哪个库,加载机制通过QT_OPENGL环境变量或者几个属性来进行判断具体使用哪个(如果不正确可能会崩溃或无法正常显示)
Qt::AA_UseDesktopOpenGL
等效于QT_OPENGL
设置为desktop
.Qt::AA_UseOpenGLES
等效于QT_OPENGL
设置为angle
.Qt::AA_UseSoftwareOpenGL
等效于QT_OPENGL
设置为software
.
注意,如果需要使用这几个属性一定要在QApplication或者QGuiApplication初始化之前设置才会生效。
windows下ANGLE在DirectX11或者DirectX9之上实现OpenGL ES 2.0 API
https://chromium.googlesource.com/angle/angle/+/master/README.md
根据不同设置运行时所依赖库也不同,对于DesktopOpenGL需要
opengl32.dll,对于UseOpenGLES则需要
libEGL.dll 和 libGLESv2.dll,对于SoftwareOpenGL 则是
opengl32sw.dll
原文:
Graphics Drivers
For Qt Quick 2 to work, a graphics driver that provides OpenGL 2.1 or higher is required. The default driver from Windows is OpenGL 1.1. Qt includes a version of the ANGLE project which is included from the Windows Qt installers. ANGLE implements the OpenGL ES 2.0 API on top of DirectX 11 or DirectX 9.
ANGLE requires that the DirectX SDK is installed when building Qt. If MSVC is used, the DirectX SDK will be provided by the Windows SDK. In this case, you will need at least Windows SDK 10. For MinGW builds, you have to install the DirectX SDK provided by Microsoft.
ANGLE chooses the render backend depending on availability. DirectX 11 is usually preferable. However, some graphics cards may not fully support it. For these cases, the environment variable QT_ANGLE_PLATFORM
(introduced in Qt 5.4) can be used to control the render backend. Possible values are d3d11
, d3d9
and warp
.
To use a custom version of ANGLE, set the ANGLE_DIR
environment variable to point to the ANGLE source tree before building Qt.
If you installed additional OpenGL drivers from your hardware vendor, then you may want to consider using this version of OpenGL instead of ANGLE. To use OpenGL, pass the command line options -opengl desktop
to the configure script.
configure -opengl desktop
To use an OpenGL ES 2.0 emulator instead of ANGLE, use the configure options: -opengl es2 -no-angle
.
configure -opengl es2 -no-angle
Dynamically Loading Graphics Drivers
In addition to the build time configuration, Qt supports choosing and loading the OpenGL implementation at runtime. To use this mode, pass -opengl dynamic
to the configure script.
configure -opengl dynamic
Note: As of Qt 5.5 this is the configuration used by the official, pre-built binary packages of Qt. It is strongly recommended to use it also in custom builds, especially for Qt binaries that are deployed alongside applications.
Note: Combining -opengl dynamic
with -static
is also possible, but be aware that ANGLE will not be statically linked into the applications in this case, it will still be built as a shared library.
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 ANGLE. This fallback will be completely transparent to the application, and will allow Qt Quick or other OpenGL code to function by translating to Direct3D. Such a fallback could, for example, take place on a Windows 7 PC with no additional graphics drivers installed. On other machines, where there is sufficient OpenGL support, the normal desktop OpenGL drivers will be used. Additionally, pure software-based OpenGL implementations may be available as additional fallbacks in the future, allowing running Qt Quick applications without a GPU.
When configured with -opengl dynamic
, neither Qt nor the applications built using qmake
will link to the opengl32 (standard desktop OpenGL) or QtANGLE libraries. Instead, the appropriate library is chosen 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 the ANGLE libraries (libEGL.dll and libGLESv2.dll) will be used. In case the ANGLE libraries are missing or initialization fails for some reason, an additional fallback is attempted by trying to load opengl32sw.dll
. See below for details.
The loading mechanism can be configured through the QT_OPENGL
environment variable and the following application attributes:
Qt::AA_UseDesktopOpenGL
Equivalent to settingQT_OPENGL
todesktop
.Qt::AA_UseOpenGLES
Equivalent to settingQT_OPENGL
toangle
.Qt::AA_UseSoftwareOpenGL
Equivalent to settingQT_OPENGL
tosoftware
.
When a certain configuration is requested explicitly, no checks are done at application startup, that is, the system-provided opengl32.dll will not be examined.
The dynamic loading has a significant impact on applications that contain native OpenGL calls: they may fail to link since qmake
no longer automatically adds opengl32.lib or libGLESv2.lib. 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.
Applications that require a certain OpenGL implementation (for example, desktop OpenGL due to relying on features provided by OpenGL 3.0 or higher) should set the application attributes Qt::AA_UseOpenGLES
or Qt::AA_UseDesktopOpenGL
before instantiating QGuiApplication or QApplication. When these attributes are set, no other OpenGL implementations are considered. Additionally, if they wish to, such applications are free to make direct OpenGL function calls by adding opengl32.lib to their .pro project files: LIBS += opengl32.lib (Visual Studio) or LIBS += -lopengl32 (MinGW). The result is, from the application's perspective, equivalent to the -opengl desktop
build configuration of Qt.
Qt::AA_UseSoftwareOpenGL
is special in the sense that it will try to load an OpenGL implementation with a non-standard name. The default name is opengl32sw.dll
. This allows shipping a software-only OpenGL implementation, for example a build of Mesa with llvmpipe, under this name. If necessary, the filename can be overridden by setting the QT_OPENGL_DLL
environment variable.
It is possible to provide a JSON-format configuration file specifying which OpenGL implementation to use depending on the graphics card and driver version. The location is given by the environment variable QT_OPENGL_BUGLIST
. Relative paths are resolved using QLibraryInfo::SettingsPath
or QStandardPaths::ConfigLocation
. The file utilizes the format of the driver bug list used in The Chromium Projects. It consists of a list of entries each of which specifies a set of conditions and a list of feature keywords. Typically, device id and vendor id are used to match a specific graphics card. They can be found in the output of the qtdiag
or dxdiag
tool.
The following feature keywords are relevant for choosing the OpenGL implementation:
disable_desktopgl
- Disables OpenGL. This ensures that Qt does not attempt to use regular OpenGL (opengl32.dll), and that it starts with ANGLE right away. This is useful to prevent bad OpenGL drivers from crashing the application.disable_angle
- Disables ANGLE. Ensures that Qt does not attempt to use ANGLE (and so Direct3D).disable_d3d11
- Disables the D3D11 rasterizer in ANGLE. Instead, the next D3D rendering option is tried first. The default order is: D3D11, D3D9, WARP, reference implementation.disable_d3d9
- Disables the D3D9 rasterizer in ANGLEdisable_rotation
- Forces the application to run in landscape orientation always. It applies to OpengGL only and has no effect when using ANGLE or Software OpenGL implementations. This is intended for drivers that have issues with rotation. This feature keyword was introduced in Qt 5.6.disable_program_cache
- Disable storing shader program binaries on disk. This feature keyword was introduced in Qt 5.12.
A sample file looks like:
{ "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" ] }, ...
When QT_OPENGL_BUGLIST
is not specified, a built-in list will be used. This typically includes some older, less-capable graphics cards with disable_desktopgl
set, in order to prevent Qt from using their unstable desktop OpenGL implementations and instead fall back to ANGLE right away.
In practice the most common combinations are expected to be the following:
disable_desktopgl
- In case the system provides OpenGL 2.0 or newer, but the driver is known to be unstable and prone to crash.disable_desktopgl
, disable_angle - When no accelerated path is desired. This ensures that the only option Qt tries is the sofware rasterizer (opengl32sw.dll). Can be useful in virtual machines and applications that are deployed on a wide range of old systems.disable_d3d11
, disable_d3d9 - When the accelerated D3D options are known to be unstable and WARP is desired (when available). Can be useful in virtual machines.
The supported keys for matching a given card or driver are the following. Note that some of these are specific to Qt.
os.type
- Operating system:win
,linux
,macosx
,android
os.version
- Kernel versionos.release
- Specifies a list of operating system releases on Windows:xp
,vista
,7
,8
,8.1
,10
.vendor_id
- Vendor from the adapter identifierdevice_id
- List of PCI device IDs.driver_version
- Driver version from the adapter identifierdriver_description
- Matches when the value is a substring of the driver description from the adapter identifiergl_vendor
- Matches when the value is a substring of theGL_VENDOR
string
To disable all blacklisting, set the environment variable QT_NO_OPENGL_BUGLIST
to any value. This will skip reading any configuration files, and instead will assume that nothing is disabled, regardless of the driver or OS.
Note: While not typically needed, QT_NO_OPENGL_BUGLIST
can become relevant in certain virtualized 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.