Add example app runner for iOS
This commit is contained in:
@@ -4,8 +4,12 @@ function(LinkAppleFrameworks TARGET)
|
|||||||
PUBLIC "-framework Foundation"
|
PUBLIC "-framework Foundation"
|
||||||
PUBLIC "-framework CoreImage"
|
PUBLIC "-framework CoreImage"
|
||||||
PUBLIC "-framework CoreVideo"
|
PUBLIC "-framework CoreVideo"
|
||||||
|
PUBLIC "-framework CoreGraphics"
|
||||||
PUBLIC "-framework Metal"
|
PUBLIC "-framework Metal"
|
||||||
PUBLIC "-framework MetalPerformanceShaders"
|
PUBLIC "-framework MetalPerformanceShaders"
|
||||||
|
PUBLIC "-framework MetalKit"
|
||||||
|
PUBLIC "-framework IOSurface"
|
||||||
|
PUBLIC "-framework QuartzCore"
|
||||||
PUBLIC "-lstdc++"
|
PUBLIC "-lstdc++"
|
||||||
PUBLIC c++
|
PUBLIC c++
|
||||||
PUBLIC c
|
PUBLIC c
|
||||||
@@ -31,9 +35,9 @@ function(LinkAppleFrameworks TARGET)
|
|||||||
target_link_libraries(${TARGET} PUBLIC ${MOBILECORESERVICES})
|
target_link_libraries(${TARGET} PUBLIC ${MOBILECORESERVICES})
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${TARGET} PUBLIC ${APPKIT})
|
target_link_libraries(${TARGET} PUBLIC ${APPKIT})
|
||||||
target_link_libraries(${TARGET} PUBLIC ${IOSURFACE})
|
|
||||||
target_link_libraries(${TARGET} PUBLIC ${QUARTZ})
|
target_link_libraries(${TARGET} PUBLIC ${QUARTZ})
|
||||||
endif()
|
endif()
|
||||||
|
target_link_libraries(${TARGET} PUBLIC ${IOSURFACE})
|
||||||
target_link_libraries(${TARGET} PUBLIC ${FOUNDATION})
|
target_link_libraries(${TARGET} PUBLIC ${FOUNDATION})
|
||||||
target_link_libraries(${TARGET} PUBLIC ${CFNETWORK})
|
target_link_libraries(${TARGET} PUBLIC ${CFNETWORK})
|
||||||
target_link_libraries(${TARGET} PUBLIC ${SYSTEMCONFIGURATION})
|
target_link_libraries(${TARGET} PUBLIC ${SYSTEMCONFIGURATION})
|
||||||
|
|||||||
23
examples/ExampleAppList.hpp
Normal file
23
examples/ExampleAppList.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ExampleApps/CubesExampleApp.hpp"
|
||||||
|
#include "ExampleApps/MovingCubeApp.hpp"
|
||||||
|
#include "ExampleApps/TexturedCubeExampleApp.hpp"
|
||||||
|
#include "ExampleApps/BillboardExampleApp.hpp"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace OpenVulkano
|
||||||
|
{
|
||||||
|
const std::vector<std::pair<const char*, IGraphicsApp*(*)()>> EXAMPLE_APPS = {
|
||||||
|
{ "Cubes Example App", &CubesExampleApp::Create },
|
||||||
|
{ "Moving Cube Example App", &MovingCubeApp::Create },
|
||||||
|
{ "Textured Cube Example App", &TexturedCubeExampleApp::Create },
|
||||||
|
{ "Billboard Example App", &BillboardExampleApp::Create }
|
||||||
|
};
|
||||||
|
}
|
||||||
19
examples/Host/iOS/ExampleViewController.h
Normal file
19
examples/Host/iOS/ExampleViewController.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "Host/iOS/OpenVulkanoViewController.h"
|
||||||
|
|
||||||
|
@interface MainMenuViewController : UIViewController
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface ExampleViewController : OpenVulkanoViewController
|
||||||
|
@property(nonatomic, strong)OpenVulkanoView* renderView;
|
||||||
|
@property size_t exampleId;
|
||||||
|
@end
|
||||||
75
examples/Host/iOS/ExampleViewController.mm
Normal file
75
examples/Host/iOS/ExampleViewController.mm
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "ExampleViewController.h"
|
||||||
|
|
||||||
|
#include "../../ExampleAppList.hpp"
|
||||||
|
|
||||||
|
@implementation MainMenuViewController
|
||||||
|
- (void)viewDidLoad {
|
||||||
|
[super viewDidLoad];
|
||||||
|
|
||||||
|
self.view.backgroundColor = [UIColor whiteColor];
|
||||||
|
|
||||||
|
CGFloat buttonHeight = 50;
|
||||||
|
CGFloat buttonSpacing = 10;
|
||||||
|
CGFloat topMargin = 50;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (const auto& app : OpenVulkano::EXAMPLE_APPS)
|
||||||
|
{
|
||||||
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||||
|
button.frame = CGRectMake(20,
|
||||||
|
topMargin + i * (buttonHeight + buttonSpacing),
|
||||||
|
self.view.bounds.size.width - 40,
|
||||||
|
buttonHeight);
|
||||||
|
[button setTitle:[NSString stringWithUTF8String:app.first] forState:UIControlStateNormal];
|
||||||
|
button.tag = i;
|
||||||
|
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
[self.view addSubview:button];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.view.frame = [UIScreen mainScreen].bounds;
|
||||||
|
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)buttonPressed:(UIButton *)sender {
|
||||||
|
ExampleViewController* example = [[ExampleViewController alloc] init];
|
||||||
|
example.exampleId = sender.tag;
|
||||||
|
example.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||||
|
[self presentViewController:example animated:true completion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidLayoutSubviews {
|
||||||
|
[super viewDidLayoutSubviews];
|
||||||
|
self.view.frame = self.view.superview.bounds;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ExampleViewController
|
||||||
|
- (void)viewDidLoad {
|
||||||
|
self.renderView = [[OpenVulkanoView alloc] initWithFrame:self.view.frame];
|
||||||
|
self.openVulkanoView = self.renderView;
|
||||||
|
[self.view addSubview:self.renderView];
|
||||||
|
[super viewDidLoad];
|
||||||
|
|
||||||
|
self.view.frame = [UIScreen mainScreen].bounds;
|
||||||
|
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidLayoutSubviews {
|
||||||
|
[super viewDidLayoutSubviews];
|
||||||
|
self.view.frame = self.view.superview.bounds;
|
||||||
|
self.renderView.frame = self.view.frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)prefersStatusBarHidden { return true; }
|
||||||
|
|
||||||
|
- (void *)makeGraphicsApp {
|
||||||
|
return OpenVulkano::EXAMPLE_APPS[self.exampleId].second();
|
||||||
|
}
|
||||||
|
@end
|
||||||
57
examples/Host/iOS/main.mm
Normal file
57
examples/Host/iOS/main.mm
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "ExampleViewController.h"
|
||||||
|
#import "Host/iOS/OpenVulkanoAppDelegate.h"
|
||||||
|
|
||||||
|
#include "Base/Logger.hpp"
|
||||||
|
|
||||||
|
@interface SceneDelegate : UIResponder<UIWindowSceneDelegate>
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SceneDelegate
|
||||||
|
@synthesize window = _window;
|
||||||
|
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
|
||||||
|
if ([scene isKindOfClass:[UIWindowScene class]]) {
|
||||||
|
UIWindowScene* wScene = (UIWindowScene*)scene;
|
||||||
|
self.window = [[UIWindow alloc] initWithWindowScene:wScene];
|
||||||
|
|
||||||
|
MainMenuViewController* rootViewController = [[MainMenuViewController alloc] init];
|
||||||
|
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
|
||||||
|
|
||||||
|
self.window.rootViewController = navigationController;
|
||||||
|
[self.window makeKeyAndVisible];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface AppDelegate : OpenVulkanoAppDelegate
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AppDelegate
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
|
// Override point for customization after application launch.
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
|
||||||
|
UISceneConfiguration *configuration = [[UISceneConfiguration alloc] initWithName:nil sessionRole:UIWindowSceneSessionRoleApplication];
|
||||||
|
configuration.delegateClass = SceneDelegate.class;
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
int main(int argCount, char** args)
|
||||||
|
{
|
||||||
|
using namespace OpenVulkano;
|
||||||
|
Logger::SetupLogger();
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
return UIApplicationMain(argCount, args, nil, NSStringFromClass([AppDelegate class]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Host/GraphicsAppManager.hpp"
|
#include "Host/GraphicsAppManager.hpp"
|
||||||
#include "ExampleApps/CubesExampleApp.hpp"
|
#include "ExampleAppList.hpp"
|
||||||
#include "ExampleApps/MovingCubeApp.hpp"
|
|
||||||
#include "ExampleApps/TexturedCubeExampleApp.hpp"
|
|
||||||
#include "ExampleApps/BillboardExampleApp.hpp"
|
|
||||||
|
|
||||||
#include <ftxui/component/captured_mouse.hpp>
|
#include <ftxui/component/captured_mouse.hpp>
|
||||||
#include <ftxui/component/component.hpp>
|
#include <ftxui/component/component.hpp>
|
||||||
@@ -22,12 +19,11 @@ using namespace OpenVulkano;
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
std::vector<std::string> examples = {
|
std::vector<std::string> examples;
|
||||||
"Cubes Example App",
|
for (const auto& e : EXAMPLE_APPS)
|
||||||
"Moving Cube Example App",
|
{
|
||||||
"Textured Cube Example App",
|
examples.emplace_back(e.first);
|
||||||
"Billboard Example App"
|
}
|
||||||
};
|
|
||||||
|
|
||||||
int selectedExample = 0;
|
int selectedExample = 0;
|
||||||
ftxui::MenuOption option;
|
ftxui::MenuOption option;
|
||||||
@@ -37,15 +33,9 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
screen.Loop(menu);
|
screen.Loop(menu);
|
||||||
|
|
||||||
std::unique_ptr<IGraphicsApp> app;
|
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
||||||
switch (selectedExample)
|
|
||||||
{
|
std::unique_ptr<IGraphicsApp> app( EXAMPLE_APPS[selectedExample].second() );
|
||||||
case 0: app = CubesExampleApp::CreateUnique(); break;
|
|
||||||
case 1: app = MovingCubeApp::CreateUnique(); break;
|
|
||||||
case 2: app = TexturedCubeExampleApp::CreateUnique(); break;
|
|
||||||
case 3: app = BillboardExampleApp::CreateUnique(); break;
|
|
||||||
default: throw std::runtime_error("Invalid menu selection!"); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsAppManager manager(app.get());
|
GraphicsAppManager manager(app.get());
|
||||||
manager.Run();
|
manager.Run();
|
||||||
|
|||||||
Reference in New Issue
Block a user