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. QOpenGLFunctions in Docker (headless OpenGL)
Forum Updated to NodeBB v4.3 + New Features

QOpenGLFunctions in Docker (headless OpenGL)

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.6k Views 4 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.
  • L Offline
    L Offline
    lukicdarkoo
    wrote on last edited by lukicdarkoo
    #1

    We have a QT-based application and we would like to run it in Docker without xvfb and without showing GUI. We want to create a headless mode, but if possible, we want to avoid dependency on xvfb.

    Approach #1: First, we tried simply by setting the QT_QPA_PLATFORM environment variable to offscreen. Although this hides the GUI on my PC it fails to create QOpenGLFunctions in Docker.

    QOpenGLContext *context = new QOpenGLContext();
    QOpenGLFunctions *gl = context->functions(); // Shows warning: "QOpenGLFunctions created with non-current context"
    

    Approach #2: Then, we tried to initialize OpenGL context (without QT) according to the following two articles:

    • https://developer.nvidia.com/blog/linking-opengl-server-side-rendering/
    • https://developer.nvidia.com/blog/egl-eye-opengl-visualization-without-x-server/

    And it works! It works in Docker and on my machine. We are able to use gl* functions without the display in Docker. Here are some details:

    GL_VENDOR=Mesa/X.org
    GL_VERSION=3.3 (Compatibility Profile) Mesa 20.2.6
    GL_RENDERER=llvmpipe (LLVM 11.0.0, 256 bits)
    GL_SHADING_LANGUAGE_VERSION=4.50
    

    Approach #3: Therefore, we tried to use our working EGL context to create QOpenGLContext:

    QOpenGLContext *context = new QOpenGLContext;
    context->setNativeHandle(QVariant::fromValue(QEGLNativeContext(ourEglContext, ourEglDisplay)));
    QOpenGLFunctions *gl = context->functions(); // Shows warning: "QOpenGLFunctions created with non-current context"
    

    But again, although it works fine on my PC I get the same warning in Docker.

    Do you have any suggestions? Does it make sense that we create a custom platform similar to the offscreen, or there is a simpler solution?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      It's outside my normal zone but Im wondering
      if approach 3 is just missing
      https://doc.qt.io/qt-5/qopenglcontext.html#makeCurrent
      with a
      https://doc.qt.io/qt-5/qoffscreensurface.html

      Again, its not something i have much experience with but i used Qt to render
      openGL mesh to images as a command line tool. Not exactly headless nor in docker
      but no harm in mentioning it.

      1 Reply Last reply
      1
      • L Offline
        L Offline
        lukicdarkoo
        wrote on last edited by lukicdarkoo
        #3

        Hi, thank you for the suggestion. You mean something like this:

        QOpenGLContext *context = new QOpenGLContext;
        context->setNativeHandle(QVariant::fromValue(QEGLNativeContext(eglCtx, eglDpy)));
        
        QOffscreenSurface *surface = new QOffscreenSurface();
        surface->setFormat(context->format());
        context->makeCurrent(surface);
        
        context->create();
        QOpenGLFunctions *gl = context->functions(); // <-- Shows the same warning
        

        But I am getting the same warning. Maybe I am missing something?

        mrjjM 1 Reply Last reply
        2
        • L lukicdarkoo

          Hi, thank you for the suggestion. You mean something like this:

          QOpenGLContext *context = new QOpenGLContext;
          context->setNativeHandle(QVariant::fromValue(QEGLNativeContext(eglCtx, eglDpy)));
          
          QOffscreenSurface *surface = new QOffscreenSurface();
          surface->setFormat(context->format());
          context->makeCurrent(surface);
          
          context->create();
          QOpenGLFunctions *gl = context->functions(); // <-- Shows the same warning
          

          But I am getting the same warning. Maybe I am missing something?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @lukicdarkoo
          Yes exactly.
          But can you check if makeCurrent returns true or false ?

          L 1 Reply Last reply
          0
          • mrjjM mrjj

            @lukicdarkoo
            Yes exactly.
            But can you check if makeCurrent returns true or false ?

            L Offline
            L Offline
            lukicdarkoo
            wrote on last edited by
            #5

            @mrjj Oh, it returns false. I will need some time to figure out why it returns false.

            1 Reply Last reply
            1
            • L Offline
              L Offline
              lukicdarkoo
              wrote on last edited by lukicdarkoo
              #6

              @mrjj I was calling the makeCurrent function before create. Here is the fixed version:

              QGuiApplication a(argc, argv);
              
              QOpenGLContext context;
              context.create();
              assert(context.isValid());  // <----- fails here
              
              QOffscreenSurface surface;
              surface.create();
              assert(surface.isValid());
              
              context.makeCurrent(&surface);
              
              QOpenGLFunctions *gl = context.functions();
              qDebug() << "Version: " << QString::fromLatin1((const char *)gl->glGetString(GL_VERSION));
              qDebug() << "Renderer: " << QString::fromLatin1((const char *)gl->glGetString(GL_RENDERER));
              

              But it also fails to create the OpenGL context in Docker. With xvfb-run and on my PC it works fine though.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi and welcome to devnet,

                Did you try to use the eglfs backend ? Since the Nvdia documentation mentions egl as system to use so you do not need an X server running.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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