diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 10f1bca..a2dbe72 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -140,9 +140,6 @@ GB_set_clock_multiplier(_gb, clockMultiplier); } current_buffer = (current_buffer + 1) % self.numberOfBuffers; - dispatch_async(dispatch_get_main_queue(), ^{ - [self setNeedsDisplay:YES]; - }); } - (uint32_t *) pixels diff --git a/Cocoa/GBViewGL.m b/Cocoa/GBViewGL.m index d678cfe..15aed08 100644 --- a/Cocoa/GBViewGL.m +++ b/Cocoa/GBViewGL.m @@ -23,4 +23,12 @@ ((GBOpenGLView *)self.internalView).openGLContext = context; } +- (void)flip +{ + [super flip]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self setNeedsDisplay:YES]; + }); +} + @end diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 34cd50b..4867d51 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -42,6 +42,7 @@ static const vector_float2 rect[] = MTKView *view = [[MTKView alloc] initWithFrame:self.frame device:(device = MTLCreateSystemDefaultDevice())]; view.delegate = self; self.internalView = view; + view.paused = YES; MTLTextureDescriptor *texture_descriptor = [[MTLTextureDescriptor alloc] init]; @@ -125,10 +126,14 @@ static const vector_float2 rect[] = - (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size { output_resolution = (vector_float2){size.width, size.height}; + dispatch_async(dispatch_get_main_queue(), ^{ + [(MTKView *)self.internalView draw]; + }); } - (void)drawInMTKView:(nonnull MTKView *)view { + if (!(view.window.occlusionState & NSWindowOcclusionStateVisible)) return; [texture replaceRegion:region mipmapLevel:0 withBytes:[self currentBuffer] @@ -188,4 +193,13 @@ static const vector_float2 rect[] = [command_buffer commit]; } + +- (void)flip +{ + [super flip]; + dispatch_async(dispatch_get_main_queue(), ^{ + [(MTKView *)self.internalView draw]; + }); +} + @end