Browse Source

Platform: don't call viewportEvent() on initialization.

In addition to 37e4f9d6f7 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.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
5013c1817a
  1. 3
      src/Platform/AbstractXApplication.cpp
  2. 5
      src/Platform/GlutApplication.h
  3. 12
      src/Platform/NaClApplication.cpp
  4. 11
      src/Platform/NaClApplication.h

3
src/Platform/AbstractXApplication.cpp

@ -113,9 +113,6 @@ int AbstractXApplication::exec() {
/* Show window */ /* Show window */
XMapWindow(display, window); XMapWindow(display, window);
/* Call viewportEvent for the first time */
viewportEvent(viewportSize);
while(!(flags & Flag::Exit)) { while(!(flags & Flag::Exit)) {
XEvent event; XEvent event;

5
src/Platform/GlutApplication.h

@ -144,6 +144,11 @@ class GlutApplication {
* Called when window size changes. You should pass the new size to * Called when window size changes. You should pass the new size to
* DefaultFramebuffer::setViewport() and possibly elsewhere (cameras, * DefaultFramebuffer::setViewport() and possibly elsewhere (cameras,
* other framebuffers...). * 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; virtual void viewportEvent(const Vector2i& size) = 0;

12
src/Platform/NaClApplication.cpp

@ -109,9 +109,6 @@ bool NaClApplication::tryCreateContext(const Configuration& configuration) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL); RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
/* Make sure viewportEvent() is called for first time */
flags |= Flag::ViewportUpdated;
c = new Context; c = new Context;
return true; return true;
} }
@ -164,14 +161,7 @@ void NaClApplication::DidChangeView(const pp::View& view) {
/* Canvas resized */ /* Canvas resized */
if(viewportSize != size) { if(viewportSize != size) {
graphics->ResizeBuffers(size.x(), size.y()); graphics->ResizeBuffers(size.x(), size.y());
viewportSize = size; viewportEvent(viewportSize = size);
flags |= Flag::ViewportUpdated;
}
/* Update viewport, if changed */
if(flags & Flag::ViewportUpdated) {
flags &= ~Flag::ViewportUpdated;
viewportEvent(size);
} }
drawEvent(); drawEvent();

11
src/Platform/NaClApplication.h

@ -261,12 +261,11 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
struct ConsoleDebugOutput; struct ConsoleDebugOutput;
enum class Flag: UnsignedByte { enum class Flag: UnsignedByte {
ViewportUpdated = 1 << 0, SwapInProgress = 1 << 0,
SwapInProgress = 1 << 1, Redraw = 1 << 1,
Redraw = 1 << 2, FullscreenSwitchInProgress = 1 << 2,
FullscreenSwitchInProgress = 1 << 3, WillBeFullscreen = 1 << 3,
WillBeFullscreen = 1 << 4, MouseLocked = 1 << 4
MouseLocked = 1 << 5
}; };
typedef Containers::EnumSet<Flag, UnsignedByte> Flags; typedef Containers::EnumSet<Flag, UnsignedByte> Flags;

Loading…
Cancel
Save