Skip to content

Commit

Permalink
Platform: test constant redraw in both SDL2 and GLFW applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Oct 5, 2024
1 parent f84deb0 commit 734ddd0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/Magnum/Platform/Test/GlfwApplicationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ struct GlfwApplicationTest: Platform::Application {
void drawEvent() override {
Debug{} << "draw event";
swapBuffers();

if(_redraw)
redraw();
}

void keyPressEvent(KeyEvent& event) override {
Expand All @@ -192,6 +195,14 @@ struct GlfwApplicationTest: Platform::Application {
if(event.key() == KeyEvent::Key::F1) {
Debug{} << "starting text input";
startTextInput();
} else if(event.key() == KeyEvent::Key::F2) {
_redraw = !_redraw;
Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled");
if(_redraw) redraw();
} else if(event.key() == KeyEvent::Key::V) {
_vsync = !_vsync;
Debug{} << "vsync" << (_vsync? "on" : "off");
setSwapInterval(_vsync ? 1 : 0);
} else if(event.key() == KeyEvent::Key::Esc) {
Debug{} << "stopping text input";
stopTextInput();
Expand Down Expand Up @@ -235,6 +246,10 @@ struct GlfwApplicationTest: Platform::Application {
void textInputEvent(TextInputEvent& event) override {
Debug{} << "text input event:" << event.text();
}

private:
bool _redraw = false;
bool _vsync = false;
};

GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments, NoCreate} {
Expand Down
25 changes: 22 additions & 3 deletions src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ struct Sdl2ApplicationTest: Platform::Application {
#endif

swapBuffers();

if(_redraw)
redraw();
}

/* For testing event coordinates */
Expand Down Expand Up @@ -228,7 +231,19 @@ struct Sdl2ApplicationTest: Platform::Application {
if(event.key() == KeyEvent::Key::F1) {
Debug{} << "starting text input";
startTextInput();
} else if(event.key() == KeyEvent::Key::Esc) {
} else if(event.key() == KeyEvent::Key::F2) {
_redraw = !_redraw;
Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled");
if(_redraw) redraw();
}
#ifndef CORRADE_TARGET_EMSCRIPTEN
else if(event.key() == KeyEvent::Key::V) {
_vsync = !_vsync;
Debug{} << "vsync" << (_vsync? "on" : "off");
setSwapInterval(_vsync ? 1 : 0);
}
#endif
else if(event.key() == KeyEvent::Key::Esc) {
Debug{} << "stopping text input";
stopTextInput();
} else if(event.key() == KeyEvent::Key::T) {
Expand Down Expand Up @@ -304,10 +319,14 @@ struct Sdl2ApplicationTest: Platform::Application {
if(event.type == SDL_WINDOWEVENT) d << event.window.event;
}

#ifdef CORRADE_TARGET_EMSCRIPTEN
private:
#ifdef CORRADE_TARGET_EMSCRIPTEN
bool _fullscreen = false;
#endif
#endif
bool _redraw = false;
#ifndef CORRADE_TARGET_EMSCRIPTEN
bool _vsync = false;
#endif
};

Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::Application{arguments, NoCreate} {
Expand Down

0 comments on commit 734ddd0

Please sign in to comment.