summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-05 12:37:43 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-05 12:37:43 -0500
commita9490274d79ecf0d7d9872c23ca4db1ac46570e6 (patch)
tree2c73ade7804ac229f9891bfef82d3971c2cfc50d
parent7e3f48153aacf5ef440797eceb748badb729cc6d (diff)
sleep before SDL_GL_SwapWindow to stop busy loop
-rw-r--r--gl.c1
-rw-r--r--main.c17
2 files changed, 12 insertions, 6 deletions
diff --git a/gl.c b/gl.c
index 5ef3360..a9850cd 100644
--- a/gl.c
+++ b/gl.c
@@ -16,6 +16,7 @@
do(VIEWPORT, Viewport)\
do(CLEARCOLOR, ClearColor)\
do(CLEAR, Clear)\
+ do(FINISH, Finish)\
do(CREATESHADER, CreateShader)\
do(DELETESHADER, DeleteShader)\
do(CREATEPROGRAM, CreateProgram)\
diff --git a/main.c b/main.c
index bba3b6b..22e7786 100644
--- a/main.c
+++ b/main.c
@@ -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);