Share QML OpenGL context and Java in Android



  • I have a Java library which I am using to render OpenGL. In order to use this library I need to pass it a EGLContext object. I am communicating from my QML app via QAndroidJniObject and would like to create a EGLContext object from JNI and pass it to my Java library. I have tried a number of things but I can't see a way of getting a native handle for the current OpenGL context. I have this code but nativeHandle() always returns an invlaid QVariant. Is this the right way to go or is there an easier way to do this?

    QQuickWindow * window;  // This is my app window from QQuick
    QOpenGLContext * context = window->openglContext();
                if (context != nullptr)
                {
                    QVariant nativeHandle = context->nativeHandle();
                    if (!nativeHandle.isNull() && nativeHandle.canConvert<QEGLNativeContext>())
                    {
                        QEGLNativeContext nativeContext = nativeHandle.value<QEGLNativeContext>();
                        EGLContext eglContext = nativeContext.context();
                        QAndroidJniObject egl("android/opengl/EGLContext", "(J)V", (jlong)*(int*)eglContext);
                        glContext = egl.object<jobject>();
                    }
                }
    


  • For anyone else stumbling upon this issue. This is marked as fixed for release in 5.9:

    https://bugreports.qt.io/browse/QTBUG-43223


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.