From e9c44739f2a89b49816b4cae5334705a01c6e15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Sep 2023 17:54:58 +0200 Subject: [PATCH] Platform: expand EmscriptenApp::GLConfiguration::Flag::PowerPreference*. It's now possible to choose between low power, high performance and default, while before it was only possible to switch between low power and high performance. The old flag is an deprecated alias to the low-power one. --- doc/changelog.dox | 9 +++++ src/Magnum/Platform/EmscriptenApplication.cpp | 9 +++-- src/Magnum/Platform/EmscriptenApplication.h | 37 +++++++++++++++---- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 638a2fe13..8df52aa7c 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -285,6 +285,10 @@ See also: @ref Platform::WindowlessGlxApplication, @ref Platform::WindowlessWglApplication and @ref Platform::Sdl2Application +- New @ref Platform::EmscriptenApplication::GLConfiguration::Flag::PowerPreferenceLowPower + and @relativeref{Platform::EmscriptenApplication::GLConfiguration,Flag::PowerPreferenceHighPerformance} + flags allowing to pick either a low power, high performance or default + behavior (see [mosra/magnum#500](https://github.com/mosra/magnum/issues/500)). @subsubsection changelog-latest-new-scenegraph SceneGraph library @@ -1181,6 +1185,11 @@ See also: @ref MeshTools::reference() and @ref MeshTools::mutableReference() were moved there as well, with @cpp Magnum/MeshTools/Reference.h @ce being a deprecated alias now. +- @cpp Platform::EmscriptenApplication::GLConfiguration::Flag::PreferLowPowerToHighPerformance @ce + is deprecated as it didn't allow explicitly choosing between high + performance and a default, use @relativeref{Platform::EmscriptenApplication::GLConfiguration,Flag::PowerPreferenceLowPower} + or @relativeref{Platform::EmscriptenApplication::GLConfiguration,Flag::PowerPreferenceHighPerformance} + instead - @cpp Shaders::DistanceFieldVector @ce, @cpp Shaders::Flat @ce, @cpp Shaders::Generic @ce, @cpp Shaders::MeshVisualizer2D @ce, @cpp Shaders::MeshVisualizer3D @ce, @cpp Shaders::Phong @ce, diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 2ddbc2129..20fc3d675 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -341,9 +341,12 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration, const !!(glConfiguration.flags() & GLConfiguration::Flag::PremultipliedAlpha); attrs.preserveDrawingBuffer = !!(glConfiguration.flags() & GLConfiguration::Flag::PreserveDrawingBuffer); - attrs.powerPreference = - !!(glConfiguration.flags() & GLConfiguration::Flag::PreferLowPowerToHighPerformance) - ? EM_WEBGL_POWER_PREFERENCE_LOW_POWER : EM_WEBGL_POWER_PREFERENCE_HIGH_PERFORMANCE; + if(glConfiguration.flags() & GLConfiguration::Flag::PowerPreferenceLowPower) + attrs.powerPreference = EM_WEBGL_POWER_PREFERENCE_LOW_POWER; + else if(glConfiguration.flags() & GLConfiguration::Flag::PowerPreferenceHighPerformance) + attrs.powerPreference = EM_WEBGL_POWER_PREFERENCE_HIGH_PERFORMANCE; + else + attrs.powerPreference = EM_WEBGL_POWER_PREFERENCE_DEFAULT; attrs.explicitSwapControl = !!(glConfiguration.flags() & GLConfiguration::Flag::ExplicitSwapControl); attrs.failIfMajorPerformanceCaveat = diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 460bda981..b91044565 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -51,6 +51,7 @@ #endif #ifdef MAGNUM_BUILD_DEPRECATED +#include /* Some APIs used to take or return a std::string before */ #include #endif @@ -967,10 +968,30 @@ class EmscriptenApplication::GLConfiguration: public GL::Context::Configuration PreserveDrawingBuffer = 1 << 1, /** - * Prefer low power to high performance. If set, the WebGL power - * preference will be set to reduce power consumption. + * Low power preference. Only at most one of + * @ref Flag::PowerPreferenceLowPower and + * @ref Flag::PowerPreferenceHighPerformance should be set. If + * neither is set, a default is used. + * @m_since_latest + */ + PowerPreferenceLowPower = 1 << 2, + + /** + * High performace power preference. Only at most one of + * @ref Flag::PowerPreferenceLowPower and + * @ref Flag::PowerPreferenceHighPerformance should be set. If + * neither is set, a default is used. + * @m_since_latest */ - PreferLowPowerToHighPerformance = 1 << 2, + PowerPreferenceHighPerformance = 1 << 3, + + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * Prefer low power to high performance + * @m_deprecated_since_latest Use @ref Flag::PowerPreferenceLowPower instead. + */ + PreferLowPowerToHighPerformance CORRADE_DEPRECATED_ENUM("use Flag::PowerPreferenceLowPower instead") = PowerPreferenceLowPower, + #endif /** * Fail if major performance caveat. If set, requests context @@ -978,32 +999,32 @@ class EmscriptenApplication::GLConfiguration: public GL::Context::Configuration * context that does not give good hardware-accelerated * performance. */ - FailIfMajorPerformanceCaveat = 1 << 3, + FailIfMajorPerformanceCaveat = 1 << 4, /** * Explicit swap control. For more details, see the * [Emscripten API reference](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenWebGLContextAttributes.explicitSwapControl). */ - ExplicitSwapControl = 1 << 4, + ExplicitSwapControl = 1 << 5, /** * Enable WebGL extensions by default. Enabled by default. For more * details, see @ref Platform-EmscriptenApplication-webgl and the * [Emscripten API reference](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenWebGLContextAttributes.enableExtensionsByDefault). */ - EnableExtensionsByDefault = 1 << 5, + EnableExtensionsByDefault = 1 << 6, /** * Render via offscreen back buffer. For more details, see the * [Emscripten API reference](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer). */ - RenderViaOffscreenBackBuffer = 1 << 6, + RenderViaOffscreenBackBuffer = 1 << 7, /** * Proxy content to main thread. For more details, see the * [Emscripten API reference](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenWebGLContextAttributes.proxyContextToMainThread). */ - ProxyContextToMainThread = 1 << 7, + ProxyContextToMainThread = 1 << 8, /** * @copydoc GL::Context::Configuration::Flag::QuietLog