vsync wait on win32 #86

Merged
MartinFouilleul merged 5 commits from vblank_notification into main 2023-09-09 12:40:00 +00:00
3 changed files with 31 additions and 29 deletions
Showing only changes of commit 5a7182a3b9 - Show all commits

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