From 734ddd0d7524208dfec2e865b07d5bc59e329769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Oct 2024 16:44:18 +0200 Subject: [PATCH] Platform: test constant redraw in both SDL2 and GLFW applications. --- .../Platform/Test/GlfwApplicationTest.cpp | 15 +++++++++++ .../Platform/Test/Sdl2ApplicationTest.cpp | 25 ++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp index 0cd9f85dce..46ef974d53 100644 --- a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp +++ b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp @@ -180,6 +180,9 @@ struct GlfwApplicationTest: Platform::Application { void drawEvent() override { Debug{} << "draw event"; swapBuffers(); + + if(_redraw) + redraw(); } void keyPressEvent(KeyEvent& event) override { @@ -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(); @@ -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} { diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index 32451fcbcc..4301d4f69d 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -199,6 +199,9 @@ struct Sdl2ApplicationTest: Platform::Application { #endif swapBuffers(); + + if(_redraw) + redraw(); } /* For testing event coordinates */ @@ -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) { @@ -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} {