From f360c19426684218006933cd1f6a60851c9dcfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 12 Oct 2021 17:54:50 +0200 Subject: [PATCH] GL: new "firefox-deprecated-debug-renderer-info" workaround. Sigh. Webdevs, could you GROW UP and be clear upfront and CONSISTENT about stuff getting deprecated?! --- doc/changelog.dox | 4 +- .../GL/Implementation/driverSpecific.cpp | 37 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 11ea92b37..198a0a507 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -88,7 +88,9 @@ See also: - Implemented @webgl_extension{WEBGL,debug_renderer_info} as @ref GL::Context::rendererStringUnmasked() and @relativeref{GL::Context,vendorStringUnmasked()} together with printing - those in the engine startup log if the extension is available + those in the engine startup log if the extension is available. It also + resulted in a new @cpp "firefox-deprecated-debug-renderer-info" @ce + workaround being added, see @ref opengl-workarounds for more info. - Recognizing @webgl_extension{EXT,float_blend} and @webgl_extension{WEBGL,debug_shaders} extensions, no implementation done yet diff --git a/src/Magnum/GL/Implementation/driverSpecific.cpp b/src/Magnum/GL/Implementation/driverSpecific.cpp index e8a11adcf..e32704756 100644 --- a/src/Magnum/GL/Implementation/driverSpecific.cpp +++ b/src/Magnum/GL/Implementation/driverSpecific.cpp @@ -31,6 +31,7 @@ #include "Magnum/Math/Range.h" #if defined(MAGNUM_TARGET_WEBGL) && defined(CORRADE_TARGET_EMSCRIPTEN) +#include #include #endif @@ -391,6 +392,15 @@ constexpr Containers::StringView KnownWorkarounds[]{ Emscripten-side part of this workaround. */ "firefox-fake-disjoint-timer-query-webgl2"_s, #endif + +#ifdef MAGNUM_TARGET_WEBGL +/* Firefox 92+ says "WEBGL_debug_renderer_info is deprecated in Firefox and + will be removed. Please use RENDERER." if attempting to use the unmasked + renderer / vendor string. The information is provided through the regular + APIs instead. Disabling the extension if present on the new versions to + avoid console spam. */ +"firefox-deprecated-debug-renderer-info"_s +#endif /* [workarounds] */ }; @@ -525,10 +535,35 @@ void Context::setupDriverWorkarounds() { if(_extensionRequiredVersion[Extensions::extension::Index] < Version::version) \ _extensionRequiredVersion[Extensions::extension::Index] = Version::version + /* Using WEBGL_debug_renderer_info results in deprecation warnings on + Firefox 92+, Firefox 92+ exposes the unmasked renderer and vendor string + through the usual APIs. Needs to be above the code that explicitly + enables the extension! */ + #if defined(MAGNUM_TARGET_WEBGL) && defined(CORRADE_TARGET_EMSCRIPTEN) + /* Assuming the extension gets eventually removed, check for Firefox + version only if the extension is actually present. Then first detect the + version and only then ask if the workaround is disabled in order to + avoid having the workaround listed as used on older versions or other + browsers */ + if(isExtensionSupported()) { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" + const Int firefoxVersion = EM_ASM_INT({ + var match = navigator.userAgent.match(/Firefox\\\\/(\\\\d+)/); + if(match) return match[1]|0; /* coerce to an int (remember asm.js?) */ + return 0; + }); + #pragma GCC diagnostic pop + if(firefoxVersion >= 92 && !isDriverWorkaroundDisabled("firefox-deprecated-debug-renderer-info"_s)) + _setRequiredVersion(WEBGL::debug_renderer_info, None); + } + #endif + /* WEBGL_debug_renderer_info needs to be explicitly requested, independently of whether Emscripten was told to implicitly request extensions or not. Has to be done before any call to detectedDriver(), - which relies on this extension. */ + which relies on this extension, but only after all other workarounds + that disable it! */ #if defined(MAGNUM_TARGET_WEBGL) && defined(CORRADE_TARGET_EMSCRIPTEN) if(isExtensionSupported()) { CORRADE_INTERNAL_ASSERT_OUTPUT(emscripten_webgl_enable_extension(emscripten_webgl_get_current_context(), "WEBGL_debug_renderer_info"));