Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] QGLWidget::makeCurrent () is per widget only or per thread?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QGLWidget::makeCurrent () is per widget only or per thread?

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 2 Posters 10.0k 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.
  • D Offline
    D Offline
    dlr2
    wrote on last edited by
    #1

    The documentation for this function says:

    void QGLWidget::makeCurrent ()

    Makes this widget the current widget for OpenGL operations, i.e. makes the widget's rendering context the current OpenGL rendering context.

    However in my experience OpenGL contexts are per thread. The question comes up because I have a single threaded application that works fine on Windows but intermittently on Linux.

    I have a QGLWidget derived class that uses the standard overloads (paintGL, etc). I am loading textures outside of the widget but within the same thread (single threaded so of course). Texture display works fine on Windows but I get a white texture on Linux (indicative of missing texture), there are no OpenGL errors occurring on the texture load.

    So, is the OpenGL context defined with makeCurrent() function really only valid in this class? Do I need to re-write so that the texture load is done in this class, with a makeCurrent() at the start of the load? Is there another approach?

    Thanks!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      As far as I know it is per thread, but I guess it never hurts to call makeCurrent(). doneCurrent() may be a different story though.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dlr2
        wrote on last edited by
        #3

        So is QGLWidget creating its own OpenGL context on initialization? Maybe I could try QGLWidget::context () in my texture loading code and then set the OpenGL context like this:

        @QGLContext *oglc = MyOGLwidget->context ();
        oglc->makeCurrent();@

        Although that would seem to be redundant since once the OpenGL context is set for a thread its not supposed to change.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dlr2
          wrote on last edited by
          #4

          ^^^ well, i see that MyOGLwidget->context () is a const pointer return and makeCurrent() is not a const member, so that doesn't work.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dlr2
            wrote on last edited by
            #5

            Well, I did fix the problem. I noticed that before QGLWidget::initializeGL() that the opengl context outside the widget and within are the same. However, after this code runs, the context comes back 0 outside of the widget. The odd this is that even though this value is the same before the widget call, the texture loaded under that context doesn't work in the widget, for Linux.

            I couldn't see anyway to get the GLuint context value from the widget for use outside the widget, so I had to rearrange my code so that texture loads are done by the widget, with a makeCurrent() call in the method. This now works on both Windows and Linux.

            I am not at all sure why this happens as generally OpenGL contexts are per thread, but there is something happening that prevents correct external contexts after initializeGL().

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Franzk
              wrote on last edited by
              #6

              Good to see you fixed it. I do wonder why the context doesn't seem to be thread specific, though.

              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

              http://www.catb.org/~esr/faqs/smart-questions.html

              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