Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Creating a QQuickView with a shared opengl context.

[SOLVED] Creating a QQuickView with a shared opengl context.

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 6.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.
  • E Offline
    E Offline
    extronus
    wrote on last edited by
    #1

    How can i create a QQuickView which shares it's context with another?

    Turgut Hakkı Özdemir

    1 Reply Last reply
    0
    • E Offline
      E Offline
      extronus
      wrote on last edited by
      #2

      It's not really an elegant solution but i think i found one.

      Before setting QML file, (setSource) connect a slot to QQuickWindow::sceneGraphInitialized() signal like this :
      @connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection);@

      when it hits the slot, do following :

      @
      openglContext()->blockSignals(true);
      openglContext()->doneCurrent();
      openglContext()->setShareContext(openGLContextToBeSharedWith);
      openglContext()->setFormat(requestedFormat());
      openglContext()->create();
      openglContext()->makeCurrent(this);
      openglContext()->blockSignals(false); // <- Forgot this line before
      @

      Turgut Hakkı Özdemir

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Martell Malone
        wrote on last edited by
        #3

        hi Turgut,

        How did you display it after extending the class?

        1 Reply Last reply
        0
        • E Offline
          E Offline
          extronus
          wrote on last edited by
          #4

          As it was.
          @
          class MyView : QQuickView
          {
          Q_OBJECT
          public :
          MyView(QWindow *parent = 0) : QQuickView(parent)
          {
          connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection);

            setPersistentOpenGLContext(true);
            backgroundContext = new QOpenGLContext(this);
            backgroundContext->setFormat(requestedFormat());
            backgroundContext->create();
            backgroundContext->makeCurrent(this);
          
            static bool openGLExtensionsInitialized = false;
            if (!openGLExtensionsInitialized) {
              OpenGL::initialize(backgroundContext);
              openGLExtensionsInitialized = true;
            }
          
            backgroundContext->doneCurrent();
          
          }
          

          protected slots :
          onSceneGraphInitialized() {
          openglContext()->blockSignals(true);
          openglContext()->doneCurrent();
          openglContext()->setShareContext(backgroundContext);
          openglContext()->setFormat(requestedFormat());
          openglContext()->create();
          openglContext()->makeCurrent(this);
          openglContext()->blockSignals(false);
          }
          protected :
          QOpenGLContext *backgroundContext;
          };

          void someInitFunction()
          {
          MyView *view = new MyView();
          view->setSource(QUrl("qrc:/script/init.qml"));
          view->show();
          app.exec();
          }
          @

          Turgut Hakkı Özdemir

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Martell Malone
            wrote on last edited by
            #5

            Many Thanks Turgut :)
            I noticed what I was missing

            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