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. Shared OpenGL context with the OpenGL context of the application UI

Shared OpenGL context with the OpenGL context of the application UI

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.4k Views
  • 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.
  • J Offline
    J Offline
    jarkko
    wrote on 16 Mar 2011, 08:49 last edited by
    #1

    Is there a way to create a shared OpenGL context with the OpenGL context of the application UI?

    Let's consider this situation:

    • We have an application with QGraphicsView as the main widget.
    • We run this application with the argument "-graphicssystem opengl".
    • Viewport of the QGraphicsView instance is QWidget.

    Inside application code I would like to:

    • Detect whether application runs with OpenGL graphicssystem.
    • If it does:
      ** Retrieve OpenGL context of the application.
      ** Create QGLWidget with shared OpenGL context with OpenGL context of the application.
    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on 16 Mar 2011, 11:06 last edited by
      #2

      First of all I have not tested this. I do not know if this is even a sensible thing to do. Having said that...

      You should be able to get this by getting a pointer to the paint engine and trying to cast it to a QGL2PaintEngineEx pointer. If that works you are running with the opengl graphicssystem.

      If the above is true, then you may be able to get the GL context by getting a pointer to the top-level widget's window surface (use QWidget::windowSurface()), and trying to cast that to a QGLWindowSurface pointer. If that works you can then call the QGLWindowSurface::context() function to get at the context.

      This uses some non-public API but it does exist. So be warned that it may change in the future. Once you have the context you can then pass it into the constructor of QGlWidget.

      Good luck with whatever you are doing and I hope it doesn't blow up ;-)

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jarkko
        wrote on 16 Mar 2011, 12:57 last edited by
        #3

        This is exactly what I was a afraid of :) There should be some way to do this with public APIs because it would help to combine Qt UI and OpenGL with minimal performance hit in a clean way. This would be useful for games and other more graphics intensive applications especially when working with mobile and embedded devices.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 16 Mar 2011, 13:08 last edited by
          #4

          I suggest you make a feature request for that on "Jira":bugreports.qt.nokia.com (check if it isn't there yet first, please). Better yet, make a patch and a merge request :-)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on 16 Mar 2011, 13:11 last edited by
            #5

            Have you tried it? Did it work? If so the MR should be fairly simple as the API looks to be there. Could probably just do with some syntactic sugar on it though. Please let us know how you get on.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jarkko
              wrote on 16 Mar 2011, 13:35 last edited by
              #6

              [quote author="ZapB" date="1300281117"]Have you tried it? Did it work? If so the MR should be fairly simple as the API looks to be there. Could probably just do with some syntactic sugar on it though. Please let us know how you get on.[/quote]

              I think I'll make a "proof-of-concept" of this. I'll let you know the results.

              I'm working on QtWebKit WebGL support. There I have to use glReadPixels() instead of drawTexture() if context for WebGL is not shared with the GL context of the viewport. It works only when QGraphicsView has QGLWidget viewport.

              This solution would require to use private APIs of the master Qt tree and it is not acceptable for QtWebKit. As far as I understand it there should not be source level dependencies between Qt tree and WebKit tree.

              [quote author="Andre" date="1300280904"]I suggest you make a feature request for that on "Jira":bugreports.qt.nokia.com (check if it isn't there yet first, please). Better yet, make a patch and a merge request :-)[/quote]

              I'll probably make that proof-of-concept patch for QtWebKit that uses the "private API" approach and put it part of the bug report. For internal change, I would probably create a patch but this needs more consideration since it needs additions to the API. Therefore patch that demonstrates the use case is better.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 16 Mar 2011, 13:37 last edited by
                #7

                Sounds like an excellent plan. Let us know how it works out please!

                1 Reply Last reply
                0

                1/7

                16 Mar 2011, 08:49

                • Login

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