From 5013c1817ab9eefcd3adacaff5f27510f5f269df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Oct 2013 18:57:53 +0200 Subject: [PATCH] Platform: don't call viewportEvent() on initialization. In addition to 37e4f9d6f7adaa7b1632caaff16b8ee897b1ced7 which did the change for Sdl2Application (because Emscripten required it), making sure that everything (except GLUT, which does it by default) behaves the same. Moreover, some applications don't expect viewport size changes at all (e.g. the app can't change size of immutable texture used for rendering) and thus the original way to defer the initialization until viewportEvent() is called would be overly complicated. Also, since framebuffer classes store viewport size in them, there is no need to call viewportEvent() on initialization. The current ways to do the initial call in Sdl2Application, *XApplication and NaClApplication were nothing more than ugly workarounds for mimicking GLUT behavior, which is bad. Lastly, to be sure that nothing breaks in user apps, I did this change in magnum-bootstrap long ago and all bootstrap application behave the right way. --- src/Platform/AbstractXApplication.cpp | 3 --- src/Platform/GlutApplication.h | 5 +++++ src/Platform/NaClApplication.cpp | 12 +----------- src/Platform/NaClApplication.h | 11 +++++------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 5b7b8bc35..591b72dfe 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -113,9 +113,6 @@ int AbstractXApplication::exec() { /* Show window */ XMapWindow(display, window); - /* Call viewportEvent for the first time */ - viewportEvent(viewportSize); - while(!(flags & Flag::Exit)) { XEvent event; diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 228e05332..67169128c 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -144,6 +144,11 @@ class GlutApplication { * Called when window size changes. You should pass the new size to * DefaultFramebuffer::setViewport() and possibly elsewhere (cameras, * other framebuffers...). + * + * Note that this function might not get called at all if the window + * size doesn't change. You are responsible for configuring the initial + * state yourself, viewport of default framebuffer can be retrieved + * from @ref DefaultFramebuffer::viewport(). */ virtual void viewportEvent(const Vector2i& size) = 0; diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index dbbdaf0a2..c3a56a45e 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -109,9 +109,6 @@ bool NaClApplication::tryCreateContext(const Configuration& configuration) { RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL); RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); - /* Make sure viewportEvent() is called for first time */ - flags |= Flag::ViewportUpdated; - c = new Context; return true; } @@ -164,14 +161,7 @@ void NaClApplication::DidChangeView(const pp::View& view) { /* Canvas resized */ if(viewportSize != size) { graphics->ResizeBuffers(size.x(), size.y()); - viewportSize = size; - flags |= Flag::ViewportUpdated; - } - - /* Update viewport, if changed */ - if(flags & Flag::ViewportUpdated) { - flags &= ~Flag::ViewportUpdated; - viewportEvent(size); + viewportEvent(viewportSize = size); } drawEvent(); diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 53d76ab07..d1de44e8c 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -261,12 +261,11 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public struct ConsoleDebugOutput; enum class Flag: UnsignedByte { - ViewportUpdated = 1 << 0, - SwapInProgress = 1 << 1, - Redraw = 1 << 2, - FullscreenSwitchInProgress = 1 << 3, - WillBeFullscreen = 1 << 4, - MouseLocked = 1 << 5 + SwapInProgress = 1 << 0, + Redraw = 1 << 1, + FullscreenSwitchInProgress = 1 << 2, + WillBeFullscreen = 1 << 3, + MouseLocked = 1 << 4 }; typedef Containers::EnumSet Flags;