Qt:如何检测正在使用哪个版本的OpenGL? [英] Qt: How to detect which version of OpenGL is being used?

查看:1310
本文介绍了Qt:如何检测正在使用哪个版本的OpenGL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt可以使用OpenGL的几种方法:桌面(本机),ANGLE,ES ...,现在有动态"可以在运行时进行选择.在应用程序中,是否可以检测到正在使用的应用程序?是在C ++中还是在QML中?

There are several ways that Qt can use OpenGL: desktop (native), ANGLE, ES... and now there's 'dynamic' which can choose at runtime. Within an app, is there a way that you can detect which one is in use? Either within C++ or within QML?

例如等同于全局声明,可让您检测操作系统

e.g. something equivalent to the global declarations that let you detect OS

推荐答案

检测OpenGL版本

  • in QML, there is OpenGLInfo
  • in C++, there is QOpenGLContext::openGLModuleType()
  • in the OpenGL C++ library, there is glGetString(GL_VERSION)
  • see also Qt blog article: Which OpenGL implementation is my Qt Quick app using today?

如果要强制使用特定的OpenGL版本

If you want to enforce a particular OpenGL version

  • 在软件中设置选项(请参见下面的代码示例)
    • 对于台式机/本机,将环境变量QT_OPENGL设置为desktop或将应用程序属性设置为Qt::AA_UseDesktopOpenGL
    • 对于ANGLE,将环境变量QT_OPENGL设置为angle或将应用程序属性设置为Qt::AA_UseOpenGLES
    • 对于软件渲染,请将环境变量QT_OPENGL设置为software或将应用程序属性设置为Qt::AA_UseSoftwareOpenGL
    • set the option in software (see code example below)
      • for desktop/native, either set the environment variable QT_OPENGL to desktop or set the application attribute to Qt::AA_UseDesktopOpenGL
      • for ANGLE, either set the environment variable QT_OPENGL to angle or set the application attribute to Qt::AA_UseOpenGLES
      • for software rendering, either set the environment variable QT_OPENGL to software or set the application attribute to Qt::AA_UseSoftwareOpenGL
      • 对于台式机/本机,请包含-opengl desktop
      • 对于ANGLE,包括-opengl选项;那是因为它是默认值
      • 还有-opengl dynamic,可让Qt选择最佳选项.这是在Qt 5.4中引入的.如果您需要此选项,但由于任何其他原因不需要静态构建,则无需创建静态构建,因为自Qt 5.5起,预编译的二进制文件都使用此选项.
      • 您还可以在 Windows版Qt-要求中探索其他变体.尽管这是Windows特定的页面,但此处包含有关为Qt配置OpenGL的许多信息. (可能是因为大多数OpenGL渲染问题都在Windows平台上!)
      • for desktop/native, include -opengl desktop
      • for ANGLE, don't include an -opengl option; that's because it is the default
      • there is also -opengl dynamic which lets Qt choose the best option. This was introduced in Qt 5.4. If you want this option but don't need a static build for any other reason, there's no need to create a static build, as the prebuilt binaries use this option since Qt 5.5.
      • there are also other variants that you can explore at Qt for Windows - Requirements. Although this is a Windows-specific page, much of the information about configuring OpenGL for Qt is contained here. (Probably because most of the OpenGL rendering issues are on the Windows platform!)
      #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();
      }
      

      (感谢 peppe 为上面评论中的初步答案,并感谢user12345的Blog链接)

      (thanks to peppe for the initial answers in the comments above and thanks to user12345 for the Blog link)

      这篇关于Qt:如何检测正在使用哪个版本的OpenGL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆