make vsync differences between win32 and macos explicit in runtime.c

This commit is contained in:
Martin Fouilleul 2023-09-09 14:34:20 +02:00
parent 6ae129022e
commit 5a7182a3b9
3 changed files with 31 additions and 29 deletions

View File

@ -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;
// }
// OCWindow* ocWindow = (OCWindow*)windowData->osx.nsWindow;
// CVReturn ret;
// if((ret = CVDisplayLinkCreateWithActiveCGDisplays(&ocWindow->displayLink)) != kCVReturnSuccess)
// {
// oc_log_error("CVDisplayLinkCreateWithActiveCGDisplays error: %d\n", ret);
// }
// CGDirectDisplayID mainDisplay = CGMainDisplayID();
// 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 = CVDisplayLinkStart(ocWindow->displayLink)) != kCVReturnSuccess)
// {
// oc_log_error("CVDisplayLinkStart ret: %d\n", ret);
// }
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(!windowData)
{
return;
}
OCWindow* ocWindow = (OCWindow*)windowData->osx.nsWindow;
CVReturn ret;
if((ret = CVDisplayLinkCreateWithActiveCGDisplays(&ocWindow->displayLink)) != kCVReturnSuccess)
{
oc_log_error("CVDisplayLinkCreateWithActiveCGDisplays error: %d\n", ret);
}
CGDirectDisplayID mainDisplay = CGMainDisplayID();
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 = CVDisplayLinkStart(ocWindow->displayLink)) != kCVReturnSuccess)
{
oc_log_error("CVDisplayLinkStart ret: %d\n", ret);
}
}

View File

@ -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);

View File

@ -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])