1 2 3 4 5 6 7 8 9 10 11 12 | SDL_DisplayMode display_mode = {0}; int display_index = SDL_GetWindowDisplayIndex(window); SDL_GetCurrentDisplayMode(display_index, &display_mode); u32 refresh_rate = (display_mode.refresh_rate == 0) ? 60 : display_mode.refresh_rate; if (SDL_GL_SetSwapInterval(-1) < 0) { if (SDL_GL_SetSwapInterval(1) < 0) { } } r32 frame_dt = 1 / refresh_rate; |
The following situations I have considered:
- Refresh rate is a fixed 60Hz. opengl has a reasonable time of 16ms to display buffer
- Refresh rate is a fixed 144Hz or 240Hz. 6.9ms or even 4.2ms seems too much of a strain for the average gpu. Is this right? Overcome this with a manual 60fps loop. Will this solution cause tearing?
- Refresh rate is variable or cannot be determined. Overcome this with a manual 60fps loop. Will this solution cause tearing?
In situations 2 or 3, the solution I can think of involves using
1 | SDL_Sleep(time_to_wait) |
1 | while (need_to_wait) ; |
Thank you!