Lately I've been trying to build a Qt/QML WebAssembly using Qt 5.15.2 ( compiled with -opengl es2 ) and Emscripten 1.39.7 with C++ on Windows.
This works as intended. I'm using a simple QML ApplicationWindow and it displays just fine. From this point I assume that if QML is able to draw something, there must be a context associated with it.
The next step for me is to grab the said context used by Qt to draw the QML Scene Graph. I then proceed to create a simple QQuickItem of my own to test that.
From what I gathered from examples all around, I set this item handleWindowChanged signal to connect the beforeSynchronizing of the new Window in charge of the said item.
Long story short, I think I am now able to query whatever is at hand for the current context, the first thing I try is to get the the current display, context and surface like so :
EGLDisplay display = eglGetCurrentDisplay();
EGLContext context = eglGetCurrentContext();
EGLSurface surface = eglGetCurrentSurface (EGL_DRAW);
But to no avail, they all return null pointers. I do not know much about Qt WebGL implementation, so at this point I think that perhaps I must query those by other means.
- QOpenGLContext
I stumble upon QOpenGLContext which I found can be retrieved from my Window ( QQuickWindow ) for instance, so in my custom item :
QOpenGLContext* qtcontext = this->window()->openglContext();
qDebug() << "openGlModuleType : " << qtcontext->openGLModuleType();
qDebug() << "openGlModuleHandle : " << qtcontext->openGLModuleHandle();
qDebug() << "shared context openGlModuleHandle ? : " << qtcontext->shareContext()->openGLModuleHandle();
Output :
openGlModuleType : 1
openGlModuleHandle : 0x0
shared context openGlModuleHandle ? : 0x0
From this I gather that the context is of type QOpenGLContext::LibGLES ( OpenGL ES 2.0 or higher ) but can't retrieve the handle apparently either way ( own or shared one ).
- QEGLNativeContext
Then, I tried another shot at QEGLNativeContext which can be made available by using the private header ( QtPlatformHeaders/QEGLNativeContext ), only to find that nativeHandle was also returning a null value :
if(qtcontext->nativeHandle() == QVariant()) qDebug() << "null native handle";
QEGLNativeContext qteglcontext = qvariant_cast<QEGLNativeContext>(qtcontext->nativeHandle());
- Emscripten
I found out that I can query the WebGL current context by Emscripten too :
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE emcontext = emscripten_webgl_get_current_context();
This seems to return a non-null value, yet I found no way to retrieve the context, display or surface handle from this.
My goal here is to retrieve a valid EGLDisplay, EGLContext and EGLSurface.
I am not really familiar with WebGL, OpenGL ES, so I think I must be doing wrong calls or simply missing the point here.
Can someone share their experience on this matter ? Or point me in the right direction ?
That'd be nice.
Have a good day all.