Sharing QOpenGLContext on devices where QSG runs on main thread
-
I have an application that runs on iOS and android and is at it's latest development phase. It uses the OpenGL under QML paradigm and has a worker thread that shares it's OpenGLContext with the QSG context in order to upload 3d stuff to the GPU in the background and do the actual drawing on the QSG thread.
While testing the app for android I noticed that on some devices the QSG thread is actually the same as the main Qt thread (the Samsung Galaxy Tab3 is an example) instead of the typical QSG running on a dedicated thread.
My problem is that on those devices I can't make the QSG context share with the context on my worker thread resulting in my program crashing.
I create an offscreen surface for my worker thread :
// this runs on the main thread as per the documentation m_surface = new QOffscreenSurface(); m_surface->create();
and then I create the context
// this runs on the worker thread m_context = new QOpenGLContext(); m_context->setShareContext(m_qsgContext); m_context->create(); m_context->makeCurrent(m_surface) QOpenGLContext::areSharing(m_context, m_qsgContext) // returns false
Is there something something special I should be aware of for these kind of devices? My code works on all the iPhones/iPads and on all the android devices I have tested (except the one mentioned above).