From 1c1cddb53e86f3e3476410f4c53f488dda7fe99d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 15 Jun 2018 20:03:59 +0300 Subject: [PATCH] OpenGL fallback --- Cocoa/GBView.m | 5 ++++- Cocoa/GBViewMetal.h | 2 +- Cocoa/GBViewMetal.m | 8 ++++++++ Makefile | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 1504cdd..a3c5a75 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -26,7 +26,10 @@ + (instancetype)allocWithZone:(struct _NSZone *)zone { if (self == [GBView class]) { - return [GBViewMetal allocWithZone: zone]; + if ([GBViewMetal isSupported]) { + return [GBViewMetal allocWithZone: zone]; + } + return [GBViewGL allocWithZone: zone]; } return [super allocWithZone:zone]; } diff --git a/Cocoa/GBViewMetal.h b/Cocoa/GBViewMetal.h index a28a343..521c3c7 100644 --- a/Cocoa/GBViewMetal.h +++ b/Cocoa/GBViewMetal.h @@ -3,5 +3,5 @@ #import "GBView.h" @interface GBViewMetal : GBView - ++ (bool) isSupported; @end diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 2bd69fe..4d2bac3 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -29,6 +29,14 @@ static const vector_float2 rect[] = vector_float2 output_resolution; } ++ (bool)isSupported +{ + if (MTLCopyAllDevices) { + return [MTLCopyAllDevices() count]; + } + return false; +} + - (void)createInternalView { MTKView *view = [[MTKView alloc] initWithFrame:self.frame device:(device = MTLCreateSystemDefaultDevice())]; diff --git a/Makefile b/Makefile index 85a92bd..9156b22 100755 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ ifeq ($(PLATFORM),Darwin) SYSROOT := $(shell xcodebuild -sdk macosx -version Path 2> /dev/null) CFLAGS += -F/Library/Frameworks OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT) -mmacosx-version-min=10.9 -LDFLAGS += -framework AppKit -framework PreferencePanes -framework Carbon -framework QuartzCore -framework Metal -framework MetalKit +LDFLAGS += -framework AppKit -framework PreferencePanes -framework Carbon -framework QuartzCore -weak_framework Metal -weak_framework MetalKit SDL_LDFLAGS := -F/Library/Frameworks -framework SDL2 -framework OpenGL endif CFLAGS += -Wno-deprecated-declarations