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. OpenGL in a different thread in Qt5
Forum Updated to NodeBB v4.3 + New Features

OpenGL in a different thread in Qt5

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.3k 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.
  • M Offline
    M Offline
    mellow
    wrote on 10 Jun 2015, 13:01 last edited by
    #1

    I am trying to migrate my correctly working software from Qt4.8 to Qt5.4, but am facing segmentation faults. I have found other people with same kinds of problems, but nobody seems to have a solution.

    I have a GLVideoWidget class that inherits QGLWidget. I need to use a swapInterval of 1 in my QGLFormat and draw 60 frames per second and thus need to do the drawing and buffer swapping in a different thread to avoid the GUI thread from stalling. I accomplished this in Qt4.8 by basically doing the following in my GLThread class:

    while(!shouldStop) {
        if(shouldSwap_) {
            glw_->makeCurrent();
            shaderProgram_.bind();
            shaderProgram_.setUniformValue("texture", 0);
            shaderProgram_.setAttributeArray("vertex", vertices_.constData());
            shaderProgram_.enableAttributeArray("vertex");
            shaderProgram_.setAttributeArray("textureCoordinate", textureCoordinates_.constData());
            shaderProgram_.enableAttributeArray("textureCoordinate");
    
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, VIDEO_WIDTH, VIDEO_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLubyte*)imBuf_);
    
            glClear(GL_COLOR_BUFFER_BIT);
            glDrawArrays(GL_TRIANGLES, 0, 6);
            glw_->swapBuffers();
    
            shaderProgram_.disableAttributeArray("vertex");
            shaderProgram_.disableAttributeArray("textureCoordinate");
            shaderProgram_.release();
            glw_->doneCurrent();
        }
    }
    

    Here glw_ is my GLVideoWidget. I have set autoBufferSwap to false so I call swapBuffers explicitely. All this worked fine before in Qt4.8, but now I get "Cannot make QOpenGLContext current in a different thread" and a segfault. Why? If I try to add context()->moveToThread(glt_); to my GLVideoWidget I get a segfault immediately. How should this be accomplished in Qt5?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RollerStevenson
      wrote on 11 Jun 2015, 18:06 last edited by RollerStevenson 6 Nov 2015, 18:08
      #2

      I'm not that familiar yet with Qt5. But some tutorials encourage to use QOpenGLWidget instead of QGLWidget as base class now. It seems to implement a different buffer handling, as the autoBufferSwap attribute does not exist anymore. This might solve your threading issues.

      1 Reply Last reply
      0

      1/2

      10 Jun 2015, 13:01

      • Login

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