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. Can I share OpenGL Context
Forum Updated to NodeBB v4.3 + New Features

Can I share OpenGL Context

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.7k 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
    epalmero
    wrote on last edited by
    #1

    Dear all:

    I have a very silly question but that will help me a lot. I am making a software to display medical images and I need to have 4 widget to pain OpenGl stuff on then. The problem is that I need to use texture and this textures can be very big so I don't want to send the texture to the OpenGL Context for each widget, instead I would like to share the OpenGl Context in the 4 widget so they can share the the texture and any other objects there. So the question is can I share the OpenGlContext between different widgets?

    Thanks a lot for the help
    Ernesto

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The exact semantics depend on which widget you actually use but yes, you can share contexts without problem.

      With QGLWidget you can pass another QGLWidget as a parameter in the "constructor":http://qt-project.org/doc/qt-5/qglwidget.html#QGLWidget and it will create a shared context.

      In Qt 5.4 QOpenGLWidget context is implicitly shared with other contexts under the same window. You can also specify an application wide flag to make all contexts shared or explicitly share selected contexts with a OpenGlContext method. More details "in the docs":http://doc-snapshot.qt-project.org/qt5-5.4/qopenglwidget.html#context-sharing

      Apart from the portable Qt methods of sharing you can always resort to platform specific calls like WGL or GLX, but there's really no need to.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        epalmero
        wrote on last edited by
        #3

        Dear Chris:

        Thanks very much for your help this is really what I need.

        Have a nice day
        Ernesto

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

          Hi Ernesto,
          I have the same problem as you faced. Have you solved this problem? I know that use the specific constructor of QGLWidget is helpful, but after geterating a new instance of QGLWidget by using that constructor, what should be done in the next?

          Thanks!
          taigw
          [quote author="epalmero" date="1417075809"]Dear Chris:

          Thanks very much for your help this is really what I need.

          Have a nice day
          Ernesto[/quote]

          1 Reply Last reply
          0
          • E Offline
            E Offline
            epalmero
            wrote on last edited by
            #5

            Hi Taigw

            When you use the share context then everytime you send a buffer in one Widget you don't need to send it in another one. I put you an example:

            Let's imaging you have 2 widgets and you want to draw the same triangle in both widget but with different color. What you do is that you send the geometry to the GPU using the QOpenGLBuffer objects in one of the Widget and you draw it using a color let's said red.

            After that you draw the second widget, if you will not share the context you will need to send the same triangle again to the GPU because the context does not know anything about that triangle. Now because you share the context you can simple use the QOpenGLBuffer that you have created in the first widget and draw the second triangle with the color that you want. You can do the same with all the object store in the Context like shaders, Buffers etc

            Best
            Ernesto

            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