summaryrefslogtreecommitdiffhomepage
path: root/main/setup.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-01 19:33:40 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-01 19:44:18 +0100
commitf9767c694e85fe774a68072f10facc5fcf4c6403 (patch)
tree2da67803cdd7ca26c2e1e67bf36d69225e4a00a0 /main/setup.cpp
parente25a350f907a3833b39b8a7629a4a880fe7b0df4 (diff)
main: reorganize frame timing code
Diffstat (limited to 'main/setup.cpp')
-rw-r--r--main/setup.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/main/setup.cpp b/main/setup.cpp
index 70b1563b..82fbb9b0 100644
--- a/main/setup.cpp
+++ b/main/setup.cpp
@@ -103,7 +103,7 @@ auto main_impl::make_gl_conf(const fm_settings&) -> GLConfiguration
.setStencilBufferSize(0);
}
-static int get_window_refresh_rate(SDL_Window* window)
+unsigned get_window_refresh_rate(SDL_Window* window, unsigned min, unsigned max)
{
fm_assert(window != nullptr);
if (int index = SDL_GetWindowDisplayIndex(window); index < 0)
@@ -111,12 +111,20 @@ static int get_window_refresh_rate(SDL_Window* window)
else if (SDL_DisplayMode dpymode{}; SDL_GetCurrentDisplayMode(index, &dpymode) < 0)
fm_warn_once("SDL_GetCurrentDisplayMode: %s", SDL_GetError());
else
- return Math::clamp(dpymode.refresh_rate, 30, 400);
- return 30;
+ {
+ fm_assert(dpymode.refresh_rate > 0 && dpymode.refresh_rate < max);
+ return (unsigned)dpymode.refresh_rate;
+ }
+ return min;
}
void main_impl::update_window_state() // todo window minimized, out of focus, fake vsync etc
{
+ auto refresh_rate = get_window_refresh_rate(window(), _frame_timings.min_refresh_rate, 10000);
+ fm_assert(refresh_rate > 0 && refresh_rate < 1000);
+ _frame_timings = {
+ .refresh_rate = refresh_rate,
+ };
}
auto main_impl::meshes() noexcept -> struct meshes