summaryrefslogtreecommitdiffstats
path: root/NativeApp
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-19 21:40:43 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-19 21:40:43 +0000
commitc1fb820bf88a05052b874d59c6470ae4b3cefe3b (patch)
tree645a2ee026d6488aca2366449a1a7c76ec642ebd /NativeApp
parentGLTFLoader: enabled creating the GLTF models without device context (diff)
downloadDiligentTools-c1fb820bf88a05052b874d59c6470ae4b3cefe3b.tar.gz
DiligentTools-c1fb820bf88a05052b874d59c6470ae4b3cefe3b.zip
MacOSAppBase: added Metal mode
Diffstat (limited to 'NativeApp')
-rw-r--r--NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard34
-rw-r--r--NativeApp/Apple/Data/OSX/Images.xcassets/metal-logo.pngbin0 -> 47327 bytes
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/GLView.m2
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/MVKView.h28
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/MVKView.m50
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/MetalView.m21
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm18
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/ViewBase.h1
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/ViewBase.m2
-rw-r--r--NativeApp/Apple/Source/Classes/OSX/ViewController.mm2
-rw-r--r--NativeApp/CMakeLists.txt3
-rw-r--r--NativeApp/include/MacOS/MacOSAppBase.hpp8
12 files changed, 160 insertions, 9 deletions
diff --git a/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard b/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard
index 9b6ac71..bc15944 100644
--- a/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard
+++ b/NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
+<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
- <deployment identifier="macosx"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -175,7 +174,7 @@
<objects>
<viewController id="lYj-9Z-eqp" customClass="ModeSelectionViewController" sceneMemberID="viewController">
<view key="view" autoresizesSubviews="NO" id="SPq-vc-rSb">
- <rect key="frame" x="0.0" y="0.0" width="350" height="255"/>
+ <rect key="frame" x="0.0" y="0.0" width="350" height="354"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zEs-tf-G2z" userLabel="OpenGL">
@@ -200,15 +199,40 @@
<action selector="goVulkan:" target="lYj-9Z-eqp" id="Vj9-0Y-bjn"/>
</connections>
</button>
+ <button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ysz-nM-ZkO" userLabel="Metal">
+ <rect key="frame" x="59" y="252" width="233" height="82"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="metal-logo" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyUpOrDown" inset="2" id="plw-eN-KbH">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ </buttonCell>
+ <connections>
+ <action selector="goMetal:" target="lYj-9Z-eqp" id="dg7-nT-7dm"/>
+ </connections>
+ </button>
</subviews>
</view>
</viewController>
<customObject id="IGK-9x-tXY" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
- <point key="canvasLocation" x="171" y="1214"/>
+ <point key="canvasLocation" x="171" y="1263"/>
+ </scene>
+ <!--View Controller-->
+ <scene sceneID="a13-Mi-ILI">
+ <objects>
+ <viewController storyboardIdentifier="MoltenVKViewControllerID" id="CK5-3d-WjT" customClass="ViewController" sceneMemberID="viewController">
+ <view key="view" id="hUH-7p-TBf" customClass="MVKView">
+ <rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </view>
+ </viewController>
+ <customObject id="WLK-iX-LX6" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="74" y="762"/>
</scene>
</scenes>
<resources>
+ <image name="metal-logo" width="650" height="650"/>
<image name="opengl-logo" width="900" height="375"/>
<image name="vulkan-logo" width="975" height="375"/>
</resources>
diff --git a/NativeApp/Apple/Data/OSX/Images.xcassets/metal-logo.png b/NativeApp/Apple/Data/OSX/Images.xcassets/metal-logo.png
new file mode 100644
index 0000000..fd4b07f
--- /dev/null
+++ b/NativeApp/Apple/Data/OSX/Images.xcassets/metal-logo.png
Binary files differ
diff --git a/NativeApp/Apple/Source/Classes/OSX/GLView.m b/NativeApp/Apple/Source/Classes/OSX/GLView.m
index 3ad9b97..04a0a9c 100644
--- a/NativeApp/Apple/Source/Classes/OSX/GLView.m
+++ b/NativeApp/Apple/Source/Classes/OSX/GLView.m
@@ -48,6 +48,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink,
{
[super awakeFromNib];
+ self.renderMode = Diligent::MacOSAppBase::RenderMode::OpenGL;
+
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFADoubleBuffer,
diff --git a/NativeApp/Apple/Source/Classes/OSX/MVKView.h b/NativeApp/Apple/Source/Classes/OSX/MVKView.h
new file mode 100644
index 0000000..fef95c5
--- /dev/null
+++ b/NativeApp/Apple/Source/Classes/OSX/MVKView.h
@@ -0,0 +1,28 @@
+/* Copyright 2015-2019 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.
+ */
+
+#include "MetalView.h"
+
+@interface MVKView : MetalView
+
+@end
diff --git a/NativeApp/Apple/Source/Classes/OSX/MVKView.m b/NativeApp/Apple/Source/Classes/OSX/MVKView.m
new file mode 100644
index 0000000..06353e4
--- /dev/null
+++ b/NativeApp/Apple/Source/Classes/OSX/MVKView.m
@@ -0,0 +1,50 @@
+/* Copyright 2015-2019 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 "MVKView.h"
+
+@implementation MVKView
+{
+}
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self)
+ {
+ self.renderMode = Diligent::MacOSAppBase::RenderMode::MoltenVK;
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder*)coder
+{
+ self = [super initWithCoder:coder];
+ if (self)
+ {
+ self.renderMode = Diligent::MacOSAppBase::RenderMode::MoltenVK;
+ }
+ return self;
+}
+
+@end
diff --git a/NativeApp/Apple/Source/Classes/OSX/MetalView.m b/NativeApp/Apple/Source/Classes/OSX/MetalView.m
index 5d4a7dd..05de9b1 100644
--- a/NativeApp/Apple/Source/Classes/OSX/MetalView.m
+++ b/NativeApp/Apple/Source/Classes/OSX/MetalView.m
@@ -28,6 +28,27 @@
{
}
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self)
+ {
+ self.renderMode = Diligent::MacOSAppBase::RenderMode::Metal;
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder*)coder
+{
+ self = [super initWithCoder:coder];
+ if (self)
+ {
+ self.renderMode = Diligent::MacOSAppBase::RenderMode::Metal;
+ }
+ return self;
+}
+
+
- (void) awakeFromNib
{
[super awakeFromNib];
diff --git a/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm b/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm
index 3bd4dbe..2d755fd 100644
--- a/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm
+++ b/NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm
@@ -66,7 +66,7 @@
- (IBAction)goVulkan:(id)sender
{
- ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MetalViewControllerID"];
+ ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MoltenVKViewControllerID"];
self.view.window.contentViewController = metalViewController;
MetalView* mtlView = (MetalView*)[metalViewController view];
@@ -80,4 +80,20 @@
[self setWindowTitle:name];
}
+- (IBAction)goMetal:(id)sender
+{
+ ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MetalViewControllerID"];
+ MetalView* mtlView = (MetalView*)[metalViewController view];
+ self.view.window.contentViewController = metalViewController;
+
+ NSString* error = [mtlView getError];
+ if(error != nil)
+ {
+ [self terminateApp:error];
+ }
+
+ NSString* name = [mtlView getAppName];
+ [self setWindowTitle:name];
+}
+
@end
diff --git a/NativeApp/Apple/Source/Classes/OSX/ViewBase.h b/NativeApp/Apple/Source/Classes/OSX/ViewBase.h
index dc357ad..82c8c00 100644
--- a/NativeApp/Apple/Source/Classes/OSX/ViewBase.h
+++ b/NativeApp/Apple/Source/Classes/OSX/ViewBase.h
@@ -30,6 +30,7 @@
@interface ViewBase : NSOpenGLView
@property CVDisplayLinkRef displayLink;
+@property Diligent::MacOSAppBase::RenderMode renderMode;
-(void)initApp:(NSView*) view;
-(void)destroyApp;
diff --git a/NativeApp/Apple/Source/Classes/OSX/ViewBase.m b/NativeApp/Apple/Source/Classes/OSX/ViewBase.m
index b73a5eb..bbc5cbb 100644
--- a/NativeApp/Apple/Source/Classes/OSX/ViewBase.m
+++ b/NativeApp/Apple/Source/Classes/OSX/ViewBase.m
@@ -58,7 +58,7 @@
// Init the application.
try
{
- _theApp->Initialize(view);
+ _theApp->Initialize((__bridge void*)view, self.renderMode);
}
catch(std::runtime_error &err)
{
diff --git a/NativeApp/Apple/Source/Classes/OSX/ViewController.mm b/NativeApp/Apple/Source/Classes/OSX/ViewController.mm
index 1a6611c..dabda9f 100644
--- a/NativeApp/Apple/Source/Classes/OSX/ViewController.mm
+++ b/NativeApp/Apple/Source/Classes/OSX/ViewController.mm
@@ -42,7 +42,7 @@
auto* view = (ViewBase*)self.view;
auto* theApp = [view lockApp];
if(theApp){
- theApp->HandleOSXEvent(theEvent, view);
+ theApp->HandleOSXEvent((__bridge void*)theEvent, (__bridge void*)view);
}
[view unlockApp];
}
diff --git a/NativeApp/CMakeLists.txt b/NativeApp/CMakeLists.txt
index 2f2c7d2..40a1500 100644
--- a/NativeApp/CMakeLists.txt
+++ b/NativeApp/CMakeLists.txt
@@ -156,6 +156,7 @@ elseif(PLATFORM_MACOS)
${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.m
+ ${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/MVKView.m
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ViewBase.m
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ViewController.mm
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ModeSelectionViewController.mm
@@ -170,6 +171,7 @@ elseif(PLATFORM_MACOS)
${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/MVKView.h
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ViewBase.h
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ViewController.h
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/OSX/ModeSelectionViewController.h
@@ -180,6 +182,7 @@ elseif(PLATFORM_MACOS)
${NATIVE_APP_SOURCE_DIR}/Apple/Data/OSX/Images.xcassets/AppIcon.appiconset/dg.icns
${NATIVE_APP_SOURCE_DIR}/Apple/Data/OSX/Images.xcassets/opengl-logo.png
${NATIVE_APP_SOURCE_DIR}/Apple/Data/OSX/Images.xcassets/vulkan-logo.png
+ ${NATIVE_APP_SOURCE_DIR}/Apple/Data/OSX/Images.xcassets/metal-logo.png
)
set(APPLE_INFO_PLIST
diff --git a/NativeApp/include/MacOS/MacOSAppBase.hpp b/NativeApp/include/MacOS/MacOSAppBase.hpp
index 32361e8..fc08fb2 100644
--- a/NativeApp/include/MacOS/MacOSAppBase.hpp
+++ b/NativeApp/include/MacOS/MacOSAppBase.hpp
@@ -33,9 +33,15 @@ namespace Diligent
class MacOSAppBase : public AppBase
{
public:
+ enum class RenderMode
+ {
+ OpenGL,
+ MoltenVK,
+ Metal
+ };
using AppBase::Update;
void Update();
- virtual void Initialize(void* view) = 0;
+ virtual void Initialize(void* view, RenderMode Mode) = 0;
virtual void HandleOSXEvent(void* event, void* view){};
protected: