wasm: Add OpenGL version check

QtQuick3D probes for the supported OpenGL level by testing
multiple OpenGL versions in descending order. Context creation
must fail for versions not supported by WebGL. It does not
appear that Emscripten does this for the 3.x minor versions,
at least.

Add version check which allows OpenGL (ES) 3.0 and 2.0.

Change-Id: Ide8745dd79e69af86812a8d6f5d6cc16ecdd099a
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Morten Johan Sørvig 2020-03-10 23:56:45 +00:00
parent d00f28afda
commit 1d5eb202b9
2 changed files with 16 additions and 4 deletions

View File

@ -62,6 +62,16 @@ QWasmOpenGLContext::~QWasmOpenGLContext()
}
}
bool QWasmOpenGLContext::isOpenGLVersionSupported(QSurfaceFormat format)
{
// Version check: support WebGL 1 and 2:
// (ES) 2.0 -> WebGL 1.0
// (ES) 3.0 -> WebGL 2.0
// [we don't expect that new WebGL versions will be created]
return ((format.majorVersion() == 2 && format.minorVersion() == 0) ||
(format.majorVersion() == 3 && format.minorVersion() == 0));
}
bool QWasmOpenGLContext::maybeCreateEmscriptenContext(QPlatformSurface *surface)
{
// Native emscripten/WebGL contexts are tied to a single screen/canvas. The first
@ -92,10 +102,8 @@ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE QWasmOpenGLContext::createEmscriptenContext(cons
attributes.failIfMajorPerformanceCaveat = false;
attributes.antialias = true;
attributes.enableExtensionsByDefault = true;
if (format.majorVersion() == 3) {
attributes.majorVersion = 2;
}
attributes.majorVersion = format.majorVersion() - 1;
attributes.minorVersion = format.minorVersion();
// WebGL doesn't allow separate attach buffers to STENCIL_ATTACHMENT and DEPTH_ATTACHMENT
// we need both or none
@ -149,6 +157,9 @@ bool QWasmOpenGLContext::isSharing() const
bool QWasmOpenGLContext::isValid() const
{
if (!(isOpenGLVersionSupported(m_requestedFormat)))
return false;
// Note: we get isValid() calls before we see the surface and can
// create a native context, so no context is also a valid state.
return !m_context || !emscripten_is_webgl_context_lost(m_context);

View File

@ -51,6 +51,7 @@ public:
QFunctionPointer getProcAddress(const char *procName) override;
private:
static bool isOpenGLVersionSupported(QSurfaceFormat format);
bool maybeCreateEmscriptenContext(QPlatformSurface *surface);
static EMSCRIPTEN_WEBGL_CONTEXT_HANDLE createEmscriptenContext(const QString &canvasId, QSurfaceFormat format);