diff --git a/src/app/osx_app.m b/src/app/osx_app.m index 145bf65..8588dac 100644 --- a/src/app/osx_app.m +++ b/src/app/osx_app.m @@ -2405,36 +2405,35 @@ void oc_vsync_init(void) void oc_vsync_wait(oc_window window) { // TODO figure out why this causes stuttering with triple buffering + oc_window_data* windowData = oc_window_ptr_from_handle(window); + if(!windowData) + { + return; + } - // oc_window_data* windowData = oc_window_ptr_from_handle(window); - // if(!windowData) - // { - // return; - // } + OCWindow* ocWindow = (OCWindow*)windowData->osx.nsWindow; - // OCWindow* ocWindow = (OCWindow*)windowData->osx.nsWindow; + CVReturn ret; - // CVReturn ret; + if((ret = CVDisplayLinkCreateWithActiveCGDisplays(&ocWindow->displayLink)) != kCVReturnSuccess) + { + oc_log_error("CVDisplayLinkCreateWithActiveCGDisplays error: %d\n", ret); + } - // if((ret = CVDisplayLinkCreateWithActiveCGDisplays(&ocWindow->displayLink)) != kCVReturnSuccess) - // { - // oc_log_error("CVDisplayLinkCreateWithActiveCGDisplays error: %d\n", ret); - // } + CGDirectDisplayID mainDisplay = CGMainDisplayID(); - // CGDirectDisplayID mainDisplay = CGMainDisplayID(); + if((ret = CVDisplayLinkSetCurrentCGDisplay(ocWindow->displayLink, mainDisplay)) != kCVReturnSuccess) + { + oc_log_error("CVDisplayLinkSetCurrentCGDisplay ret: %d\n", ret); + } - // if((ret = CVDisplayLinkSetCurrentCGDisplay(ocWindow->displayLink, mainDisplay)) != kCVReturnSuccess) - // { - // oc_log_error("CVDisplayLinkSetCurrentCGDisplay ret: %d\n", ret); - // } + if((ret = CVDisplayLinkSetOutputCallback(ocWindow->displayLink, oc_display_link_callback, ocWindow)) != kCVReturnSuccess) + { + oc_log_error("CVDisplayLinkSetOutputCallback ret: %d\n", ret); + } - // if((ret = CVDisplayLinkSetOutputCallback(ocWindow->displayLink, oc_display_link_callback, ocWindow)) != kCVReturnSuccess) - // { - // oc_log_error("CVDisplayLinkSetOutputCallback ret: %d\n", ret); - // } - - // if((ret = CVDisplayLinkStart(ocWindow->displayLink)) != kCVReturnSuccess) - // { - // oc_log_error("CVDisplayLinkStart ret: %d\n", ret); - // } + if((ret = CVDisplayLinkStart(ocWindow->displayLink)) != kCVReturnSuccess) + { + oc_log_error("CVDisplayLinkStart ret: %d\n", ret); + } } diff --git a/src/graphics/graphics_surface.c b/src/graphics/graphics_surface.c index 88175d7..b938d19 100644 --- a/src/graphics/graphics_surface.c +++ b/src/graphics/graphics_surface.c @@ -148,10 +148,7 @@ oc_surface oc_surface_create_for_window(oc_window window, oc_surface_api api) if(surface) { surfaceHandle = oc_surface_handle_alloc(surface); - // On windows, we do a manual wait for vsync in runtime.c so just turn all the swap intervals off -#if OC_PLATFORM_WINDOWS - oc_surface_swap_interval(surfaceHandle, 0); -#endif + oc_surface_swap_interval(surfaceHandle, 1); oc_surface_select(surfaceHandle); } return (surfaceHandle); diff --git a/src/runtime.c b/src/runtime.c index a6dc482..7ee08d3 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -209,6 +209,8 @@ i32 orca_surface_callback(void* user) data->surface = oc_surface_create_for_window(data->window, data->api); #if OC_PLATFORM_WINDOWS + //NOTE(martin): on windows we set all surfaces to non-synced, and do a single "manual" wait here. + // on macOS each surface is individually synced to the monitor refresh rate but don't block each other oc_surface_swap_interval(data->surface, 0); #endif @@ -839,7 +841,11 @@ i32 orca_runloop(void* user) oc_arena_clear(oc_scratch()); +#if OC_PLATFORM_WINDOWS + //NOTE(martin): on windows we set all surfaces to non-synced, and do a single "manual" wait here. + // on macOS each surface is individually synced to the monitor refresh rate but don't block each other oc_vsync_wait(app->window); +#endif } if(exports[OC_EXPORT_TERMINATE])