Qt6 topics merged with General

OpenGL resources

  • As I learned from docs, Qt OpenGL resources (QOpenGLBuffer, QOpenGLShader etc.) must be initialized and destroyed in the same OpenGL context. And there is one context for each QOpenGLWidget. So do I have to create, say, one QOpenGLBuffer for each widget? A buffer may contain a lot of data. May I use a single buffer in many widgets?

  • Lifetime Qt Champion


    Are you looking for context resource sharing ?

  • Yes, thanks!

    Correct me if I'm wrong:
    Suppose I have contexts c1 and c2, and c1 is the current context. So I can create OpenGL resourses I don't want to share between contexts, then call setShareContext(c2) and create resourses that will be shared. After that, there will be no way to create resourses that won't be shared, and there will be no way to break the share group.

    And one more question: if I have a shared resourse, when should I destroy it? Which context must be current during the destruction?

  • Can I share any kind of OpenGL resource? It appears that buffers can be shared while Vertex Array Objects cannot.

  • Lifetime Qt Champion

    From the documentation of QOpenGLVertexArrayObject:

    Note: Vertex Array Objects, like all other OpenGL container objects, are specific to the context for which they were created and cannot be shared amongst a context group.

    It's specific to the container objects.

  • Thanks again! But what about destruction of OpenGL objects in "share group" of contexts? They probably must be destroyed when any of those contexts is current?

  • Lifetime Qt Champion

    AFAIK, the manipulation of the objects must always be done with a valid context so the current one.

Log in to reply