MacOS Mojave test and fix

This commit is contained in:
Carlos Aragones 2021-04-28 14:11:13 +02:00
parent dbd882ed22
commit ffc5f5b503
3 changed files with 19 additions and 3 deletions

View File

@ -103,7 +103,7 @@ resize_dst(SWindowData *window_data, uint32_t width, uint32_t height) {
window_data->dst_height = (uint32_t) (height * window_data->factor_height); window_data->dst_height = (uint32_t) (height * window_data->factor_height);
} }
#if !defined(USE_OPENGL_API) #if !defined(USE_OPENGL_API) && !defined(USE_METAL_API)
//------------------------------------- //-------------------------------------
void void

View File

@ -297,6 +297,7 @@ mfb_update_events(struct mfb_window *window) {
//------------------------------------- //-------------------------------------
extern double g_time_for_frame; extern double g_time_for_frame;
extern bool g_use_hardware_sync;
bool bool
mfb_wait_sync(struct mfb_window *window) { mfb_wait_sync(struct mfb_window *window) {
@ -312,6 +313,10 @@ mfb_wait_sync(struct mfb_window *window) {
return false; return false;
} }
if(g_use_hardware_sync) {
return true;
}
@autoreleasepool { @autoreleasepool {
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific; SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
if(window_data_osx == 0x0) { if(window_data_osx == 0x0) {

View File

@ -80,6 +80,10 @@ NSString *g_shader_src = kShader(
// Setup command queue // Setup command queue
command_queue = [metal_device newCommandQueue]; command_queue = [metal_device newCommandQueue];
id<MTLCommandBuffer> commandBuffer = [command_queue commandBuffer];
if ([commandBuffer respondsToSelector:@selector(presentDrawable:afterMinimumDuration:)]) {
g_use_hardware_sync = true;
}
[self _createShaders]; [self _createShaders];
[self _createAssets]; [self _createAssets];
@ -169,9 +173,16 @@ NSString *g_shader_src = kShader(
//------------------------------------- //-------------------------------------
- (void) drawInMTKView:(nonnull MTKView *) view { - (void) drawInMTKView:(nonnull MTKView *) view {
if (g_target_fps_changed) { if (g_target_fps_changed) {
view.preferredFramesPerSecond = (int) (1.0 / g_time_for_frame); // MacOS is ignoring this :()
if (g_time_for_frame == 0) {
// Contrary to what is stated in the documentation,
// 0 means that it does not update.
view.preferredFramesPerSecond = 9999;
}
else {
view.preferredFramesPerSecond = (int) (1.0 / g_time_for_frame);
}
g_target_fps_changed = false; g_target_fps_changed = false;
g_use_hardware_sync = true;
} }
// Wait to ensure only MaxBuffersInFlight number of frames are getting proccessed // Wait to ensure only MaxBuffersInFlight number of frames are getting proccessed