Browse Source

Platform: sync EmscriptenApp canvas size setup for the contextless case.

It was just completely wrong there, probably just forgot to update that.
pull/491/head
Vladimír Vondruš 5 years ago
parent
commit
fa31077789
  1. 3
      doc/changelog.dox
  2. 24
      src/Magnum/Platform/EmscriptenApplication.cpp

3
doc/changelog.dox

@ -270,6 +270,9 @@ See also:
- Fixed @ref Platform::GlfwApplication, @ref Platform::Sdl2Application and
@ref Platform::EmscriptenApplication to correctly print app-specified DPI
scaling in its verbose output
- Fixed canvas size setup in @ref Platform::EmscriptenApplication to be the
same in the @ref Platform::EmscriptenApplication::Configuration::WindowFlag::Contextless "Contextless"
case as for a WebGL-enabled context
@subsection changelog-latest-deprecated Deprecated APIs

24
src/Magnum/Platform/EmscriptenApplication.cpp

@ -319,11 +319,29 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration) {
_canvasTarget = (_deprecatedTargetBehavior ? "" : "#") + canvasId();
_dpiScaling = dpiScaling(configuration);
/* Get CSS canvas size and cache it. This is used later to detect canvas
resizes in emscripten_set_resize_callback() and fire viewport events,
because browsers are only required to fire resize events on the window
and not on particular DOM elements. */
_lastKnownCanvasSize = windowSize();
/* By default Emscripten creates a 300x150 canvas. That's so freaking
random I'm getting mad. Use the real (CSS pixels) canvas size instead,
if the size is not hardcoded from the configuration. This is then
multiplied by the DPI scaling. */
Vector2i canvasSize;
if(!configuration.size().isZero()) {
const Vector2i scaledCanvasSize = configuration.size()*_dpiScaling;
emscripten_set_canvas_element_size(_canvasTarget.data(), scaledCanvasSize.x(), scaledCanvasSize.y());
canvasSize = configuration.size();
/* Because hardcoding canvas size for WebGL is usually a wrong thing to
do, notify about that in the verbose output */
Debug{verbose} << "Platform::EmscriptenApplication::tryCreate(): hardcoded canvas size" << canvasSize;
} else {
canvasSize = _lastKnownCanvasSize;
Debug{verbose} << "Platform::EmscriptenApplication::tryCreate(): autodetected canvas size" << canvasSize;
}
_dpiScaling = dpiScaling(configuration);
const Vector2i scaledCanvasSize = canvasSize*_dpiScaling*_devicePixelRatio;
emscripten_set_canvas_element_size(_canvasTarget.data(), scaledCanvasSize.x(), scaledCanvasSize.y());
setupCallbacks(!!(configuration.windowFlags() & Configuration::WindowFlag::Resizable));
setupAnimationFrame(!!(configuration.windowFlags() & Configuration::WindowFlag::AlwaysRequestAnimationFrame));

Loading…
Cancel
Save