Georg Georg - 1 year ago 117
C++ Question

OpenGl instanced rendering in Qt5

I am trying to render many objects through instancing. However the function


seems to have been removed in Qt5. It exists in the QOpenGLFunctions class in Qt4, but not in Qt5.

What is the correct way to use instancing in Qt5 then?

Answer Source

There's no such thing as QOpenGLFunctions in Qt 4 (QOpenGL* classes have been all introduced in Qt 5).

Both of your links are indeed pointing at two different Qt 5 classes: QOpenGLFunctions_4_2_Core and QOpenGLFunctions.

And both of those classes are OpenGL function resolvers, so you can write something like:

// get the object from somewhere (usually, a QOpenGLContext)
QOpenGLFunctions *functions = ...

The difference between them is:

  • QOpenGLFunctions aims at the "common subset" between OpenGL ES 2 and OpenGL 2.1 + FBO. So it will work both on "desktop" and "embedded", provided you're fine with that subset; you can develop on your desktop computer and then deploy to embedded and you won't need to change your GL code. (In theory.)
  • QOpenGLExtraFunctions aims at the "common subset" between OpenGL ES 3.1 and OpenGL 4.3 (?). Same thing, but bigger version, so more features: compute shaders, draw indirect, samplers, immutable textures, transform feedback, and the like. A subset of it will still work if you only have OpenGL 2 or 3, provided you've got the right extensions.
  • QOpenGLFunctions_4_2_Core, and all the other similar _X_Y_Profile classes, only work in a Desktop OpenGL context compatible with the class name (for instance, 4_2_Core will work with any OpenGL context whose version is equal or bigger than 4.2, and Core or Compatibility profile).

If you want to use instancing, you can choose either a suitable QOpenGLFUnctions_X_Y_Profile if you only aim desktop (so you need at least version 3.1), or QOpenGLExtraFunctions. Both have glDrawArraysInstanced.