Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QOpenGLShaderProgram in different Threads and QOpenGLContexts [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

QOpenGLShaderProgram in different Threads and QOpenGLContexts [SOLVED]

Scheduled Pinned Locked Moved Game Development
2 Posts 1 Posters 2.5k 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.
  • S Offline
    S Offline
    Seraph
    wrote on last edited by
    #1

    Hi together,

    I am using QOpenGLShaderProgram objects to compile, link and bind my OpenGL shaders which works pritty awesome!
    The thing is that i have more than one rendering thread with different QOpenGLContexts each.

    Now the problem:
    Each thread needs to have the shaders (which are mostly the same!) and i encapsulated the compile and link step into a separate method which is part of my derived QOpenGLShaderProgram class. This method will be called if the renderer accesses the shader the first time. But the renderer is in a different thread. So i get this message:
    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QOpenGLShaderProgram(0x5e0884), parent's thread is QThread(0x6e9d98), current thread is QThread(0x5d1860) )

    So i guess that QOpenGLShader program is instantiating new QOpenGLShader instances and sets itself as the parent!?

    Now my question:
    Is there a possibility to either deactivate adding new child objects in QOpenGLShader program or can i somehow share the shaders between different QOpenGLContexts? Thus, that the graphics card has to compile the shader only once and each thread just has to call QOpenGLShaderProgram::bind()!?

    The second solution would be the finest! But i don't know if it is possible or how to make it!

    Thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seraph
      wrote on last edited by
      #2

      I solved the problem. I just create a new QOpenGLShader program instance for each thread once it renders the object the first time.

      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