diff --git a/libs/app/include/psemek/app/app.hpp b/libs/app/include/psemek/app/app.hpp index c7ea2539..4714ef49 100644 --- a/libs/app/include/psemek/app/app.hpp +++ b/libs/app/include/psemek/app/app.hpp @@ -30,8 +30,9 @@ namespace psemek::app scene * set_scene(scene * s); void show_cursor(bool show); - float time() const; + void vsync(bool on); + float time() const; int width() const; int height() const; diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index c56a378b..fa32331e 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -242,6 +242,23 @@ namespace psemek::app return std::chrono::duration_cast>(clock::now() - impl().start_time).count(); } + void app::vsync(bool on) + { + if (on) + { + // try adaptive vsync + if (SDL_GL_SetSwapInterval(-1) != 0) + { + // failed, try usual vsync then + SDL_GL_SetSwapInterval(1); + } + } + else + { + SDL_GL_SetSwapInterval(0); + } + } + int app::width() const { return impl().width;