Refactor app creation for better iOS support

This commit is contained in:
2023-07-28 18:09:11 +02:00
parent deaf45f429
commit 13cefdf9f8
5 changed files with 19 additions and 4 deletions

View File

@@ -95,7 +95,12 @@ public:
void Close() override{}
};
std::unique_ptr<openVulkanoCpp::IGraphicsApp> CubesExampleApp::Create()
openVulkanoCpp::IGraphicsApp* CubesExampleApp::Create()
{
return new CubesExampleAppImpl();
}
std::unique_ptr<openVulkanoCpp::IGraphicsApp> CubesExampleApp::CreateUnique()
{
return std::make_unique<CubesExampleAppImpl>();
}

View File

@@ -12,5 +12,7 @@
class CubesExampleApp : public openVulkanoCpp::IGraphicsApp
{
public:
static std::unique_ptr<openVulkanoCpp::IGraphicsApp> Create();
static openVulkanoCpp::IGraphicsApp* Create();
static std::unique_ptr<openVulkanoCpp::IGraphicsApp> CreateUnique();
};

View File

@@ -12,6 +12,7 @@
/** The main view controller for the demo storyboard. */
@interface OpenVulkanoViewController : UIViewController
-(void*) makeGraphicsApp;
@end

View File

@@ -90,6 +90,10 @@ public:
std::unique_ptr<IGraphicsApp> app;
}
-(void*) makeGraphicsApp {
return CubesExampleApp::Create();
}
-(void) dealloc {
manager->ShutDown();
[_displayLink release];
@@ -106,7 +110,10 @@ public:
auto sizeX = size.width * self.view.contentScaleFactor;
auto sizeY = size.height * self.view.contentScaleFactor;
window.Init(self.view.layer, {sizeX, sizeY});
app = CubesExampleApp::Create();
//TODO check if type is correct
IGraphicsApp* appPtr = static_cast<IGraphicsApp*>(self.makeGraphicsApp);
if (!appPtr) throw std::runtime_error("Failed to create graphics app");
app = std::unique_ptr<IGraphicsApp>(appPtr);
manager = new GraphicsAppManager(app.get(), &window);
manager->StartUp();

View File

@@ -12,7 +12,7 @@ using namespace openVulkanoCpp;
int main(int argc, char** argv)
{
std::unique_ptr<IGraphicsApp> app = CubesExampleApp::Create();
std::unique_ptr<IGraphicsApp> app = CubesExampleApp::CreateUnique();
GraphicsAppManager manager(app.get());
manager.Run();
return 0;