问:如何检测正在使用的OpenGL版本?

Pau*_*one 6 opengl qt qt5

Qt可以通过多种方式使用OpenGL:桌面(本机),ANGLE,ES ......现在可以在运行时选择"动态".在应用程序中,有没有办法可以检测到哪一个正在使用?在C++内还是在QML中?

例如,等同于允许您检测OS 的全局声明的东西

Pau*_*one 12

检测OpenGL版本

如果您想强制执行特定的 OpenGL 版本

  • 在软件中设置选项(参见下面的代码示例)
    • 对于桌面/本机,请将环境变量设置QT_OPENGLdesktop或将应用程序属性设置为Qt::AA_UseDesktopOpenGL
    • 对于 ANGLE,将环境变量设置QT_OPENGLangle或将应用程序属性设置为Qt::AA_UseOpenGLES
    • 对于软件渲染,将环境变量设置QT_OPENGLsoftware或将应用程序属性设置为Qt::AA_UseSoftwareOpenGL
  • 使用configure设置您想要的 OpenGL 实现的选项创建 Qt 的静态构建(但请注意Qt 许可规则
    • 对于桌面/本机,包括 -opengl desktop
    • 对于 ANGLE,不要包含-opengl选项;那是因为它是默认的
    • 还有-opengl dynamic让 Qt 选择最佳选项的方法。这是在 Qt 5.4 中引入的。如果您需要此选项但由于任何其他原因不需要静态构建,则无需创建静态构建,因为预构建的二进制文件自 Qt 5.5 起使用此选项。
    • 您还可以在Qt for Windows-Requirements 中探索其他变体。尽管这是一个特定于 Windows 的页面,但这里包含了很多关于为 Qt 配置 OpenGL 的信息。(可能是因为大部分 OpenGL 渲染问题都在 Windows 平台上!)

代码示例

#include <QGuiApplication>
//...

int main(int argc, char *argv[])
{
    // Set the OpenGL type before instantiating the application
    // In this example, we're forcing use of ANGLE.

    // Do either one of the following (not both). They are equivalent.
    qputenv("QT_OPENGL", "angle");
    QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);

    // Now instantiate the app
    QGuiApplication app(argc, argv);
    //...

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

(感谢peppe在上述评论中的初步回答,并感谢 user12345 提供博客链接)