Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make multiple QGLWidgets share the same QGLContext?
Forum Updated to NodeBB v4.3 + New Features

How to make multiple QGLWidgets share the same QGLContext?

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 7.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zhaopeng
    wrote on last edited by
    #1

    Maybe this is an old question, but I can not find any workable solution.
    I have tried the approach as follow according to the Qt document.
    Create a QGLContext and pass it to QGLWidget's constructor
    @
    QGLContext*glContext=new QGLContext (QGLFormat::defaultFormat());

    glContext->create();// create() always fail without painter device

    QGLWidget * glWidget=new QGLWidget(glContext,this);//OK, context becomes valid

    QGLWidget * glWidget1=new QGLWidget(glContext,this);
    @
    When passing the context to the second QGLWidget, error "QGLWidget::setContext: Context must refer to this widget" is produced.
    It seems a context can only be used by one widget.

    Some suggest that use the second widget as shared widget of first one.
    @
    QGLWidget * glWidget=new QGLWidget(QGLFormat::defaultFormat(),this);

    QGLWidget * glWidget1=new QGLWidget(QGLFormat::defaultFormat(),this,glWidget);
    @
    But the context is not shared , only display list and texture objects are shared. Right?
    Any workable solution?
    Thanks!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi

      [quote author="zhaopeng" date="1356013406"]

      Some suggest that use the second widget as shared widget of first one.
      [/quote]

      This solution is working. It's the one I always use.

      [quote author="zhaopeng" date="1356013406"]

      But the context is not shared , only display list and texture objects are shared.[/quote]

      What do you mean? Display lists and texture object are the only things "share-able" with OpenGL contexts. There is nothing more.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zhaopeng
        wrote on last edited by
        #3

        Thanks for your reply!

        [quote author="tilsitt" date="1356013956"]
        What do you mean? Display lists and texture object are the only things "share-able" with OpenGL contexts. There is nothing more.[/quote]

        I know the FBO can not be shared. How about VBO, VAO, UBO, Transform feedback buffer and so on? There are many kinds of resources of OpenGL. What I worry about is that some of them can not be shared and I have to make a big change of my program.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tilsitt
          wrote on last edited by
          #4

          From "OpenGL 4.3 Core Profile specification":http://www.opengl.org/registry/doc/glspec43.core.20120806.pdf:

          bq. Objects that may be shared between contexts include buffer objects, program
          and shader objects, renderbuffer objects, sampler objects, sync objects, and texture
          objects (except for the texture objects named zero).
          Objects which contain references to other objects include framebuffer, program
          pipeline, query, transform feedback, and vertex array objects. Such objects are
          called container objects and are not shared.

          (chaper 5 page 47 about context sharing)

          So "true" objects like textures or buffer objects are shared. Containers that reference other objects (e.g. a FBO references a texture as color buffer) are not shared.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zhaopeng
            wrote on last edited by
            #5

            You mean the sharing of QGLContext follows the latest OpenGL specification, right? Now it's clear and I can rest to use it. Thanks a lot!

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tilsitt
              wrote on last edited by
              #6

              [quote author="zhaopeng" date="1356080913"]You mean the sharing of QGLContext follows the latest OpenGL specification, right?[/quote]

              Yes, that's what I mean.

              [quote author="zhaopeng" date="1356080913"]Thanks a lot![/quote]

              You're welcome ;)

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zhaopeng
                wrote on last edited by
                #7

                Sorry, I got another question. Can the sharing relationship be propagated and commutated? For example
                @ QGLWidget * glWidget=new QGLWidget(QGLFormat::defaultFormat(),this);
                QGLWidget * glWidget1=new QGLWidget(QGLFormat::defaultFormat(),this,glWidget);
                QGLWidget * glWidget2=new QGLWidget(QGLFormat::defaultFormat(),this,glWidget1);@

                glWidget is the share widget of glWidget1. According to the Qt doc glWidget1 will share its OpenGL resources with glWidget, which can be accessed in glWidget. How about glWidget's OpenGL resources? Can they be accessed in glWidget1?
                Then glWidget1 is passed as share widget to glWidget2, so how about the relationship between glWidget and glWidget2.

                Thanks!

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tilsitt
                  wrote on last edited by
                  #8

                  When a gl widget has another one as sharing gl widget, both of them are pointing to a unique set of share-able resources (it's like sharing smart pointers): glWidget, glWidget1 and glWidget2 all work on a unique set of resources. So, yes glWidget can "access" glWidget1 and glWidget2, glWidget1 can "access" glWidget and glWidget2 and glWidget2 can "access" glWidget and glWidget1. For what I can say, there is no limitation in the number of gl widget sharing the same resources.

                  F 1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    zhaopeng
                    wrote on last edited by
                    #9

                    [quote author="tilsitt" date="1356098680"]When a gl widget has another one as sharing gl widget, both of them are pointing to a unique set of share-able resources (it's like sharing smart pointers): glWidget, glWidget1 and glWidget2 all work on a unique set of resources. So, yes glWidget can "access" glWidget1 and glWidget2, glWidget1 can "access" glWidget and glWidget2 and glWidget2 can "access" glWidget and glWidget1. For what I can say, there is no limitation in the number of gl widget sharing the same resources.[/quote]

                    Great! Thank you for being such a big help! :)

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      Kantharaj
                      wrote on last edited by
                      #10

                      I have a problem in sharing a GLContext between two GLWidgets,
                      I have Dual monitor system which has got NVidia Graphics Card, Monitors are configured as Screen 0 & Screen 1 ( Separate X Screens). and i am trying to create one GLwidget on Screen 0 and the second GLWidget on Screen 1, if Both GLWidgets are at same screen i am able to share the context but if i create a second GLWidget on Screen 1 context is not sharing. Advance Thanks for any help.

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        zhaopeng
                        wrote on last edited by
                        #11

                        Are your two monitors connected to the same Nvidia card? I think the context can not be shared if each monitor has its own graphics card unless using SLI.

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          Kantharaj
                          wrote on last edited by
                          #12

                          Hi zhaopeng!
                          The two monitors are connected to same Nvidia Card and the both are configured as two screens.

                          1 Reply Last reply
                          0
                          • Z Offline
                            Z Offline
                            zhaopeng
                            wrote on last edited by
                            #13

                            Hi,
                            It may be a big problem for me because I also have a plan to use dual monitor. I will give a try when another monitor is available and report the result.

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              Kantharaj
                              wrote on last edited by
                              #14

                              Thank you very much for your time!!

                              1 Reply Last reply
                              0
                              • T tilsitt

                                When a gl widget has another one as sharing gl widget, both of them are pointing to a unique set of share-able resources (it's like sharing smart pointers): glWidget, glWidget1 and glWidget2 all work on a unique set of resources. So, yes glWidget can "access" glWidget1 and glWidget2, glWidget1 can "access" glWidget and glWidget2 and glWidget2 can "access" glWidget and glWidget1. For what I can say, there is no limitation in the number of gl widget sharing the same resources.

                                F Offline
                                F Offline
                                Feiz
                                wrote on last edited by
                                #15

                                @tilsitt you sure it can run right?

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved