本文介绍了Qt 5中的OpenGL与QOpenGL/QtOpenGL:区别和局限性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为有两种方法将OpenGL与 Qt 5 一起使用(/ QtOpenGL a>包装器和常规的 OpenGL API),我想知道每一个都有哪些局限性.有人可以告诉我我应该知道的QOpenGL包装器是否有限制吗?

Since there are two ways to use OpenGL with Qt 5 (QOpenGL/QtOpenGL wrapper and regular OpenGL API), I wonder what are the limitations of each one. Could someone tell if there are limitations with QOpenGL wrapper that I should be aware of?

之所以这样问,是因为我不想开始使用QOpenGL包装器,却发现我无法使用OpenGL API的全部功能.有没有人同时拥有这方面的经验,并且可以在功能,性能和易用性方面提供一些提示?

The reason I am asking this is because I don't want to start using QOpenGL wrapper and find out that I can't use the full capability of OpenGL API. Does anyone have experience with both and could provide some hints in terms of capability, performance and ease of use?

推荐答案

好吧,Qt 5.0的OpenGL包装器是基于OpenGL ES(嵌入式系统)2.0规范构建的,该规范本质上是桌面OpenGL 3.0规范的简化版本. Qt选择此规范是为了促进可移植性,因为它已得到移动平台的广泛支持,并且几乎在所有现代PC上均受支持.如果选择使用Qt包装器,则必须解决OpenGL ES 2.0规范的缺点,该缺点大部分属于以下类别:

Well, Qt 5.0's OpenGL wrappers are built on top of the OpenGL ES (Embedded Systems) 2.0 specification which is essentially a watered down version of the desktop OpenGL 3.0 specification. Qt chose this specification to facilitate portability as it is widely supported by mobile platforms in addition being supported on nearly all modern PCs. If you choose to use the Qt wrappers you have to work around the shortcomings of the OpenGL ES 2.0 specification which, for the most part, fall into the following categories:

  1. 没有固定功能的管道功能. (没有转换堆栈,glBeginglEndglLightf等.)
  2. 不支持高级OpenGL 3+功能或仅在扩展中支持. (纹理缓冲对象,计算着色器,原子负载存储纹理,镶嵌着色器,统一缓冲对象等.)
  3. 缺少某些纹理格式(整数纹理,图像纹理等)
  4. GLSL语法和语义. (缺少布局限定符,通过highplowp声明的数据精度要求,等等.)
  5. 缺少一些便捷方法. (glBlitFramebufferglMultiDrawArraysglDrawRangeElements等.)
  1. No fixed-function pipeline capabilities. (no transformation stack, glBegin,glEnd,glLightf,etc..)
  2. No support for advanced OpenGL 3+ capabilities or support only in extensions. (texture buffer objects, compute shaders, atomic load-store textures, tessellation shaders, uniform buffer objects etc..)
  3. Lack of certain texture formats (integer textures, image textures, etc..)
  4. Small differences in GLSL syntax & semantics. (lack of layout qualifiers, data precision requirements via highp, lowp declarations, etc..)
  5. Lack of some convenience methods. (glBlitFramebuffer,glMultiDrawArrays, glDrawRangeElements, etc..)

有关OpenGL ES 2.0规范的完整说明,请此处.

For a full description of the OpenGL ES 2.0 specification look here.

但是,这种功能的缺乏并不意味着Qt包装器无法完成您所需的工作.尽管OpenGL ES 2.0缺少许多有用的功能,但是您仍然可以完成整个OpenGL规范所允许的99%的工作.如果您决定通过自定义包装程序使用桌面OpenGL规范,则Qt仍然可以管理创建和通过使用QGLFormat类来对桌面OpenGL上下文进行窗口化.

However, This lack of features does not mean that the Qt wrappers can not accomplish what you need. Although OpenGL ES 2.0 is missing a lot of helpful functionality, you can still accomplish 99% of what the full desktop OpenGL specification would allow. If you decide to utilize a desktop OpenGL specification via custom wrappers, Qt can still manage the creation & windowing of desktop OpenGL contexts through the use of the QGLFormat class.

请记住,如果您决定使用桌面OpenGL包装器,并在Qt应用程序中使用它们,则Qt提供的某些类可能会干扰自定义包装器的操作.例如,在QGLWidget上进行QPainter操作可能会利用OpenGL ES规范的功能,并且可能会干扰包装对象的操作.

Keep in mind that if you decide to use desktop OpenGL wrappers, and utilize these within a Qt application, some classes provided by Qt may interfere with the operation of your custom wrappers. For example, QPainter operations on a QGLWidget may utilize functionality of the OpenGL ES specification and might interfere with the operation of your wrapper objects.

就个人而言,我更喜欢使用自定义OpenGL包装器,因为我更喜欢桌面OpenGL规范,因为功能集定义得更好,并且它们提供了解决问题的更多选择.另一方面,Qt 5提供了一些绝对出色的体系结构,用于使用OpenGL ES创建快速,强大的动态用户界面. (通过QtQuick 2和QML)

Personally, I prefer to use custom OpenGL wrappers as I greatly prefer the desktop OpenGL specifications as the feature sets are better defined and they provide more options to tackle a problem with. On the other hand, Qt 5 provides some absolutely fantastic architectures for making quick, powerful dynamic user interfaces using OpenGL ES. (Through by QtQuick 2 and QML)

哪种API最适合您的需求,基本上取决于您是否以嵌入式或移动平台为目标(在这种情况下,您必须使用OpenGL ES),以及是否愿意牺牲额外的开发时间来编写和维护自定义OpenGL 3个以上的包装器.

Which API suits your needs best essentially comes down to whether or not you are targeting embedded or mobile platforms (in which case your forced to use OpenGL ES), and whether you are willing to sacrifice additional development time writing and maintaining custom OpenGL 3+ wrappers.

这篇关于Qt 5中的OpenGL与QOpenGL/QtOpenGL:区别和局限性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 20:55