diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-05 12:37:43 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-05 12:37:43 -0500 |
commit | a9490274d79ecf0d7d9872c23ca4db1ac46570e6 (patch) | |
tree | 2c73ade7804ac229f9891bfef82d3971c2cfc50d /main.c | |
parent | 7e3f48153aacf5ef440797eceb748badb729cc6d (diff) |
sleep before SDL_GL_SwapWindow to stop busy loop
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -341,7 +341,7 @@ int main(int argc, char **argv) { #if DEBUG //printf("\033[H\033[2J"); #endif - PROFILE_TIME(frame_start); + double frame_start = time_get_seconds(); SDL_Event event; @@ -643,19 +643,24 @@ int main(int argc, char **argv) { buffer_check_valid(&ted->buffers[i]); buffer_check_valid(&ted->line_buffer); #endif - - PROFILE_TIME(frame_end_noswap); - + + glFinish(); + + double frame_end_noswap = time_get_seconds(); #if PROFILE { print("Frame (noswap): %.1f ms\n", (frame_end_noswap - frame_start) * 1000); } #endif - - + + u32 ms_wait = (u32)((frame_end_noswap - frame_start) * 1000); + if (ms_wait) ms_wait -= 1; // give swap an extra ms to make sure it's actually vsynced + SDL_Delay(ms_wait); SDL_GL_SwapWindow(window); PROFILE_TIME(frame_end); + assert(glGetError() == 0); + #if PROFILE { print("Frame: %.1f ms\n", (frame_end - frame_start) * 1000); |