QOpenGLWidget with a common OpenGL context?

I have an existing OpenGL context that I would like to share with the new QOpenGLWidget.

I know I can do this:

  • Create QOpenGLWidget
  • Wait for initializeGL to be called and save context
  • Create a new QOpenGLContext and share it with the saved context.

However, I would like to do it in a different order:

  • Create QOpenGLContext
  • Create a QOpenGLWidget by exposing the existing context and making them public.

Is it possible?

+4
source share
1 answer

Edit, I know little about QOpenGLFramebufferObject, but ignore the previous content.

In QOpenGLWidget, it always sets its context for sharing with its nearest top-level window (or itself, if it is a window). You are right in your understanding that there is no way to change the context of a QOpenGLWidget participant without subclassing it in order to completely change the way it works. In the QOpenGLWidgetPrivate :: initialize () function, the context is initialized from the standard Format and top-level shareContext. If you want to work with a context before creating a QOpenGLWidget, then it must be through a global general context. Qt :: AA_ShareOpenGLContexts must be set before creating the QGuiApplication object.

You need to wait while QGuiApplication initializes the global context before trying to access it. Since global_share_context is a static member of the QOpenGLContext class, you can simply create any QOpenGLContext and access it through context.globalShareContext (). Then just delete the original QOpenGLContext. Any QOpenGLWidget you create will share this context. If you can find a way to get a pointer to a global common context before creating () your own special context, you can just share it with the global context, and you're good to go, since sharing takes place in both directions. The exchange is carried out through the whole group of common contexts that are shared with each other, so sharing the same context with the whole group.

In addition, I do not know that this does not change anything, but QOpenGLContext says that it can share framebuffer objects.

+2
source

Source: https://habr.com/ru/post/990012/


All Articles