diff options
Diffstat (limited to 'Common/NativeApp')
| -rw-r--r-- | Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard | 14 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/GLView.h | 2 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/GLView.m | 2 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.h | 33 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.mm (renamed from Common/NativeApp/Apple/Source/Classes/OSX/MetalView.mm) | 77 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.h (renamed from Common/NativeApp/Apple/Source/Classes/OSX/MetalView.h) | 17 | ||||
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.mm | 55 | ||||
| -rw-r--r-- | Common/NativeApp/CMakeLists.txt | 33 |
8 files changed, 147 insertions, 86 deletions
diff --git a/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard b/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard index 312b53d..04f3d53 100644 --- a/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard +++ b/Common/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard @@ -71,12 +71,6 @@ <action selector="runToolbarCustomizationPalette:" target="Ady-hI-5gd" id="pQI-g3-MTW"/> </connections> </menuItem> - <menuItem title="Metal" id="d28-Qb-Hbb" userLabel="Metal"> - <modifierMask key="keyEquivalentModifierMask"/> - <connections> - <segue destination="VWH-wR-9QD" kind="modal" id="S5M-I6-cmz"/> - </connections> - </menuItem> </items> </menu> </menuItem> @@ -143,7 +137,7 @@ </connections> </window> <connections> - <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/> + <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="p8t-OE-KhS"/> </connections> </windowController> <customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> @@ -153,7 +147,7 @@ <!--View Controller--> <scene sceneID="hIz-AP-VOD"> <objects> - <viewController id="XfG-lQ-9wD" sceneMemberID="viewController"> + <viewController storyboardIdentifier="GLViewControllerID" id="XfG-lQ-9wD" sceneMemberID="viewController"> <view key="view" id="m2S-Jp-Qdl" userLabel="GL View" customClass="GLView"> <rect key="frame" x="0.0" y="0.0" width="800" height="600"/> <autoresizingMask key="autoresizingMask"/> @@ -166,8 +160,8 @@ <!--Metal View Controller--> <scene sceneID="JAO-pz-Td3"> <objects> - <viewController id="VWH-wR-9QD" customClass="MetalViewController" sceneMemberID="viewController"> - <view key="view" id="0v6-SX-xCX" customClass="MetalView"> + <viewController storyboardIdentifier="MetalViewControllerID" id="VWH-wR-9QD" customClass="MetalViewController" sceneMemberID="viewController"> + <view key="view" id="0v6-SX-xCX" customClass="MTKView"> <rect key="frame" x="0.0" y="0.0" width="800" height="600"/> <autoresizingMask key="autoresizingMask"/> </view> diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h index 993334d..7ef94fb 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h +++ b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h @@ -17,6 +17,6 @@ -(void)stopDisplayLink; -(void)startDisplayLink; -(NSString*)getAppName; -- (NSString*)getError; +-(NSString*)getError; @end diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m index 79aad2f..fac04b8 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m +++ b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m @@ -12,7 +12,9 @@ #import "GLView.h" #include "NativeAppBase.h" +#ifndef SUPPORT_RETINA_RESOLUTION #define SUPPORT_RETINA_RESOLUTION 1 +#endif @interface GLView () { diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.h b/Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.h new file mode 100644 index 0000000..53b2a63 --- /dev/null +++ b/Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.h @@ -0,0 +1,33 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#import <AppKit/AppKit.h> +#import <MetalKit/MetalKit.h> + +// Implementation of MTKViewDelegate +@interface MTKRenderer : NSObject<MTKViewDelegate> + +- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView; + +@end + diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.mm b/Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.mm index e8f6837..175c46d 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.mm +++ b/Common/NativeApp/Apple/Source/Classes/OSX/MTKRenderer.mm @@ -21,71 +21,46 @@ * of the possibility of such damages. */ -#include <memory> - -#import "MetalView.h" -#import <QuartzCore/CAMetalLayer.h> +#import <MTKRenderer.h> +#include <memory> #include "NativeAppBase.h" -#pragma mark - -#pragma mark MetalViewController - -@implementation MetalViewController +// Main class performing the rendering +@implementation MTKRenderer { std::unique_ptr<NativeAppBase> _theApp; } --(void) viewDidLoad { - [super viewDidLoad]; - - self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method. - - _theApp.reset(CreateApplication()); - _theApp->Initialize(self.view); - - // Temporary - _theApp->Update(); - _theApp->Render(); - _theApp->Present(); -} - -// Resize the window to fit the size of the content as set by the sample code. -/*-(void) viewWillAppear { - [super viewWillAppear]; - - CGSize vSz = self.view.bounds.size; - NSWindow *window = self.view.window; - NSRect wFrm = [window contentRectForFrameRect: window.frame]; - NSRect newWFrm = [window frameRectForContentRect: NSMakeRect(wFrm.origin.x, wFrm.origin.y, vSz.width, vSz.height)]; - [window setFrame: newWFrm display: YES animate: window.isVisible]; - [window center]; -}*/ - -@end - - -#pragma mark - -#pragma mark MetalView - -@implementation MetalView - -// Indicates that the view wants to draw using the backing layer instead of using drawRect:. --(BOOL) wantsUpdateLayer +/// Initialize with the MetalKit view from which we'll obtain our Metal device +- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView { - return YES; + self = [super init]; + if(self) + { + _theApp.reset(CreateApplication()); + _theApp->Initialize(mtkView); + } + + return self; } -// Returns a Metal-compatible layer. -+(Class) layerClass +/// Called whenever view changes orientation or is resized +- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size { - return [CAMetalLayer class]; + NSRect viewRectPoints = [view bounds]; + NSRect viewRectPixels = [view convertRectToBacking:viewRectPoints]; + + _theApp->WindowResize(viewRectPixels.size.width, viewRectPixels.size.height); } -// If the wantsLayer property is set to YES, this method will be invoked to return a layer instance. --(CALayer*) makeBackingLayer +/// Called whenever the view needs to render a frame +- (void)drawInMTKView:(nonnull MTKView *)view { - return [self.class.layerClass layer]; + _theApp->Update(); + _theApp->Render(); + _theApp->Present(); } @end + diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.h b/Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.h index b17d7f3..bfe4a01 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/MetalView.h +++ b/Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.h @@ -21,20 +21,15 @@ * of the possibility of such damages. */ +#if defined(TARGET_IOS) +#import <UIKit/UIKit.h> +#define PlatformViewController UIViewController +#else #import <AppKit/AppKit.h> - -#pragma mark - -#pragma mark MetalViewController +#define PlatformViewController NSViewController +#endif // The main view controller for the app storyboard. @interface MetalViewController : NSViewController -@end - -#pragma mark - -#pragma mark MetalView - -// The Metal-compatibile view for the app Storyboard. -@interface MetalView : NSView @end - diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.mm b/Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.mm new file mode 100644 index 0000000..a3d821f --- /dev/null +++ b/Common/NativeApp/Apple/Source/Classes/OSX/MetalViewController.mm @@ -0,0 +1,55 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#import "MetalViewController.h" +#import "MTKRenderer.h" + +@implementation MetalViewController +{ + MTKView *_view; + MTKRenderer *_renderer; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Set the view to use the default device + _view = (MTKView *)self.view; + + _renderer = [[MTKRenderer alloc] initWithMetalKitView:_view]; + + if(!_renderer) + { + NSLog(@"Renderer failed initialization"); + return; + } + + // Initialize our renderer with the view size + [_renderer mtkView:_view drawableSizeWillChange:_view.drawableSize]; + + _view.delegate = _renderer; +} + +@end + diff --git a/Common/NativeApp/CMakeLists.txt b/Common/NativeApp/CMakeLists.txt index 05be689..148d967 100644 --- a/Common/NativeApp/CMakeLists.txt +++ b/Common/NativeApp/CMakeLists.txt @@ -140,7 +140,8 @@ elseif(PLATFORM_MACOS) ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/AppDelegate.m ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/FullscreenWindow.m ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/GLView.m - ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MetalView.mm + ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MetalViewController.mm + ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MTKRenderer.mm ) set_source_files_properties(${APPLE_SOURCE} PROPERTIES COMPILE_FLAGS "-x objective-c++" @@ -151,7 +152,8 @@ elseif(PLATFORM_MACOS) ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/AppDelegate.h ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/FullscreenWindow.h ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/GLView.h - ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MetalView.h + ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MetalViewController.h + ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MTKRenderer.h ) set(APPLE_RESOURCES @@ -184,20 +186,25 @@ elseif(PLATFORM_MACOS) if (NOT CORE_VIDEO) message(FATAL_ERROR "CoreVideo not found") endif() - target_link_libraries(${TARGET_NAME} PRIVATE ${OPENGL_LIBRARY} ${CORE_VIDEO}) + target_link_libraries(${TARGET_NAME} PRIVATE ) - if(VULKAN_SUPPORTED) - find_library(METAL_FRAMEWORK Metal) - if (NOT METAL_FRAMEWORK) - message(FATAL_ERROR "Metal framework not found") - endif() - find_library(CORE_ANIMATION QuartzCore) - if (NOT CORE_ANIMATION) - message(FATAL_ERROR "QuartzCore (CoreAnimation) not found") - endif() - target_link_libraries(${TARGET_NAME} PRIVATE ${METAL_FRAMEWORK} ${CORE_ANIMATION}) + find_library(METAL_FRAMEWORK Metal) + if (NOT METAL_FRAMEWORK) + message(FATAL_ERROR "Metal framework not found") + endif() + + find_library(CORE_ANIMATION QuartzCore) + if (NOT CORE_ANIMATION) + message(FATAL_ERROR "QuartzCore (CoreAnimation) not found") endif() + find_library(METAL_KIT MetalKit) + if (NOT METAL_FRAMEWORK) + message(FATAL_ERROR "MetalKit framework not found") + endif() + + target_link_libraries(${TARGET_NAME} PRIVATE ${OPENGL_LIBRARY} ${CORE_VIDEO} ${METAL_FRAMEWORK} ${CORE_ANIMATION} ${METAL_KIT}) + endfunction() function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS) |
