macOS: Fix MoltenVK Metal view resizing, and allow the metal view to be used without vulkan.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h
index 2257c3c..bb8bb5b 100644
--- a/include/SDL_config_macosx.h
+++ b/include/SDL_config_macosx.h
@@ -184,7 +184,12 @@
#endif
#ifndef SDL_VIDEO_RENDER_METAL
+/* Metal only supported on 64-bit architectures with 10.11+ */
+#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
#define SDL_VIDEO_RENDER_METAL 1
+#else
+#define SDL_VIDEO_RENDER_METAL 0
+#endif
#endif
/* Enable OpenGL support */
@@ -209,7 +214,7 @@
#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
#define SDL_VIDEO_VULKAN 1
#else
-#define SDL_VIDEO_VULKAN 0
+#define SDL_VIDEO_VULKAN 0
#endif
/* Enable system power support */
diff --git a/src/video/cocoa/SDL_cocoametalview.h b/src/video/cocoa/SDL_cocoametalview.h
index 745dea3..8550ebe 100644
--- a/src/video/cocoa/SDL_cocoametalview.h
+++ b/src/video/cocoa/SDL_cocoametalview.h
@@ -32,11 +32,11 @@
#import "../SDL_sysvideo.h"
#import "SDL_cocoawindow.h"
-#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
+#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
-#include <Cocoa/Cocoa.h>
-#include <Metal/Metal.h>
-#include <QuartzCore/CAMetalLayer.h>
+#import <Cocoa/Cocoa.h>
+#import <Metal/Metal.h>
+#import <QuartzCore/CAMetalLayer.h>
#define METALVIEW_TAG 255
@@ -57,7 +57,7 @@ SDL_cocoametalview* Cocoa_Mtl_AddMetalView(SDL_Window* window);
void Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h);
-#endif /* SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA */
+#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
#endif /* SDL_cocoametalview_h_ */
diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m
index 562eecc..8078803 100644
--- a/src/video/cocoa/SDL_cocoametalview.m
+++ b/src/video/cocoa/SDL_cocoametalview.m
@@ -28,7 +28,7 @@
#import "SDL_cocoametalview.h"
-#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
+#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
#include "SDL_assert.h"
@@ -44,7 +44,7 @@
}
/* Indicate the view wants to draw using a backing layer instead of drawRect. */
--(BOOL) wantsUpdateLayer
+- (BOOL)wantsUpdateLayer
{
return YES;
}
@@ -52,7 +52,7 @@
/* When the wantsLayer property is set to YES, this method will be invoked to
* return a layer instance.
*/
--(CALayer*) makeBackingLayer
+- (CALayer*)makeBackingLayer
{
return [self.class.layerClass layer];
}
@@ -74,8 +74,9 @@
}
/* Set the size of the metal drawables when the view is resized. */
-- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
- [super resizeSubviewsWithOldSize:oldSize];
+- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
+{
+ [super resizeWithOldSuperviewSize:oldSize];
[self updateDrawableSize];
}
@@ -123,6 +124,6 @@ Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h)
}
}
-#endif /* SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA */
+#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
/* vi: set ts=4 sw=4 expandtab: */