Reputation: 722
I have a very simple Qt/OpenGL setup, where my GUI thread can request texture upload in a worker thread. The worker thread is signaling back as soon as the texture is available and the GUI thread can then work with it.
Unfortunately, it seems like sometimes it takes up to ~50ms for the texture to be fully available for sharing in the GUI context. In this case, a part of the bound texture appears black. Introducing a waiting timer effectively solves the problem, but naturally slows down the processing. There is no obvious pattern to the required waiting time, so I was wondering if there was a way to find out if a texture is in fact ready to be bound in the shared context.
My setup looks as follows:
Early in the application I make sure the globalShareContext
is available by calling
QCoreApplication::setAttribute( Qt::AA_ShareOpenGLContexts );
In the worker thread I create a context and hook it to the globalShareContext
QOpenGLContext context;
context->setShareContext( QOpenGLContext::globalShareContext() );
I then use one of the QOpenGLTexture
's upload functionality to move the texture data to the GPU and eventually bind it in the GUI thread.
Upvotes: 2
Views: 602
Reputation: 45332
Unfortunately, it seems like sometimes it takes up to ~50ms for the texture to be fully available for sharing in the GUI context.
You have a couple of issues here
A quick&dirty fix would be to add a glFinish()
command after the texture upload, which will force the GL to process all the commands which are still in the queue and block the calling thread until completion.
However, a much better solution are OpenGL Sync Objects.
Upvotes: 2