summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);