16

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?

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Maiss
  • 1,641
  • 4
  • 18
  • 23
  • 2
    this question is incredibly relevant to anyone who try to use Qt and opengl. So yes it is constructive. – UmNyobe Dec 18 '15 at 10:09

1 Answers1

18

I don't want to start using QOpenGL wrapper and find out that I can't use the full capability of OpenGL API

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. 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..)

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

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.

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.

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)

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.

Sir Digby Chicken Caesar
  • 3,063
  • 1
  • 23
  • 31
  • Is the answer the same if I would use OpenGL 4.1 in both ways? I believe you can use the QOpenGL wrapper with 4.1 functionality by setting the context version (i.e., QGLFormat::setVersion(4,1)) and calling OpenGL 4.1 classes. – Maiss Mar 28 '13 at 04:10
  • 1
    You can create an OpenGL 4.1 context with Qt, but you will find that some of the Qt wrappers were designed for the OpenGL ES specification and don't support certain functionality. For example, the `QOpenGLFramebufferObject` class does not support multiple target rendering. – Sir Digby Chicken Caesar Mar 28 '13 at 04:18
  • Is there a difference in speed? If using the opengl api, will functions be faster than using the Qopengl, or is it the same? – user-2147482637 Feb 12 '14 at 08:36
  • Well, it depends on what version of the Opengl standard you would be utilizing. If you were using Desktop OpenGL 3+ you may definitely see some performance gains from using QOpenGL when rendering complex scenes. When rendering simple scenes, the difference in performance than can be achieved when using OpenGL 3+ over OpenGL ES 2.0 is fairly negligible. – Sir Digby Chicken Caesar Feb 17 '14 at 03:52