Skip to content

Commit

Permalink
macOS: Fix MoltenVK Metal view resizing, and allow the metal view to …
Browse files Browse the repository at this point in the history
…be used without vulkan.
  • Loading branch information
slime73 committed Dec 31, 2017
1 parent 6d32ebd commit 48fea0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
7 changes: 6 additions & 1 deletion include/SDL_config_macosx.h
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down
10 changes: 5 additions & 5 deletions src/video/cocoa/SDL_cocoametalview.h
Expand Up @@ -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

Expand All @@ -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_ */

Expand Down
13 changes: 7 additions & 6 deletions src/video/cocoa/SDL_cocoametalview.m
Expand Up @@ -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"

Expand All @@ -44,15 +44,15 @@ + (Class)layerClass
}

/* Indicate the view wants to draw using a backing layer instead of drawRect. */
-(BOOL) wantsUpdateLayer
- (BOOL)wantsUpdateLayer
{
return YES;
}

/* 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];
}
Expand All @@ -74,8 +74,9 @@ - (instancetype)initWithFrame:(NSRect)frame
}

/* 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];
}

Expand Down Expand Up @@ -123,6 +124,6 @@ - (void)updateDrawableSize
}
}

#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: */

0 comments on commit 48fea0c

Please sign in to comment.