make it possible to create set app for GraphicsAppManager in deferred mode
This commit is contained in:
@@ -19,6 +19,8 @@ using namespace OpenVulkano;
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
GraphicsAppManager manager;
|
||||||
|
|
||||||
std::vector<std::string> examples;
|
std::vector<std::string> examples;
|
||||||
for (const auto& e : EXAMPLE_APPS)
|
for (const auto& e : EXAMPLE_APPS)
|
||||||
{
|
{
|
||||||
@@ -36,8 +38,7 @@ int main(int argc, char** argv)
|
|||||||
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
||||||
|
|
||||||
std::unique_ptr<IGraphicsApp> app( EXAMPLE_APPS[selectedExample].second() );
|
std::unique_ptr<IGraphicsApp> app( EXAMPLE_APPS[selectedExample].second() );
|
||||||
|
manager.SetApp(app.get());
|
||||||
GraphicsAppManager manager(app.get());
|
|
||||||
manager.Run();
|
manager.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,65 +24,64 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
using clock = std::chrono::steady_clock;
|
using clock = std::chrono::steady_clock;
|
||||||
|
|
||||||
|
GraphicsAppManager::GraphicsAppManager(RenderAPI::RenderApi renderApi) { Init(nullptr, nullptr, renderApi); }
|
||||||
|
|
||||||
GraphicsAppManager::GraphicsAppManager(OpenVulkano::IGraphicsApp* app, RenderAPI::RenderApi renderApi)
|
GraphicsAppManager::GraphicsAppManager(OpenVulkano::IGraphicsApp* app, RenderAPI::RenderApi renderApi)
|
||||||
: app(app), renderApi(renderApi)
|
: app(app), renderApi(renderApi)
|
||||||
{
|
{
|
||||||
Utils::SetThreadName("Main");
|
Init(app, nullptr, renderApi);
|
||||||
#ifdef HAS_TRACY
|
|
||||||
ZoneScoped;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
Logger::SetupLogger();
|
|
||||||
if (!app)
|
|
||||||
{
|
|
||||||
constexpr auto msg = "The app must not be null!";
|
|
||||||
Logger::MANAGER->error(msg);
|
|
||||||
throw std::runtime_error(msg);
|
|
||||||
}
|
|
||||||
platform = std::unique_ptr<IPlatform>(PlatformProducer::CreatePlatform(renderApi));
|
|
||||||
window = platform->MakeWindow();
|
|
||||||
renderer = std::unique_ptr<IRenderer>(PlatformProducer::CreateRenderManager(renderApi));
|
|
||||||
app->SetGraphicsAppManager(this);
|
|
||||||
window->SetWindowHandler(this);
|
|
||||||
inputManager = Input::InputManager::GetInstance();
|
|
||||||
engineConfig = EngineConfiguration::GetEngineConfiguration();
|
|
||||||
engineConfig->OnFpsCapChanged += EventHandler(this, &GraphicsAppManager::UpdateCappedFpsInfo);
|
|
||||||
// set initial values
|
|
||||||
if (engineConfig->GetFpsCap() > 0)
|
|
||||||
{
|
|
||||||
UpdateCappedFpsInfo(engineConfig->GetFpsCap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAppManager::GraphicsAppManager(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi)
|
GraphicsAppManager::GraphicsAppManager(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi)
|
||||||
: app(app), renderApi(renderApi)
|
: app(app), renderApi(renderApi)
|
||||||
|
{
|
||||||
|
Init(app, window, renderApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsAppManager::SetApp(IGraphicsApp* app)
|
||||||
|
{
|
||||||
|
this->app = app;
|
||||||
|
app->SetGraphicsAppManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsAppManager::Init(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi)
|
||||||
{
|
{
|
||||||
Utils::SetThreadName("Main");
|
Utils::SetThreadName("Main");
|
||||||
#ifdef HAS_TRACY
|
#ifdef HAS_TRACY
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Logger::SetupLogger();
|
Logger::SetupLogger();
|
||||||
if (!app)
|
Logger::MANAGER->info("Initializing graphics app manager ...");
|
||||||
{
|
this->renderApi = renderApi;
|
||||||
constexpr auto msg = "The app must not be null!";
|
platform = std::unique_ptr<IPlatform>(PlatformProducer::CreatePlatform(renderApi));
|
||||||
Logger::MANAGER->error(msg);
|
|
||||||
throw std::runtime_error(msg);
|
|
||||||
}
|
|
||||||
//platform = std::unique_ptr<IPlatform>(PlatformProducer::CreatePlatform(renderApi));
|
|
||||||
this->window = window;
|
|
||||||
renderer = std::unique_ptr<IRenderer>(PlatformProducer::CreateRenderManager(renderApi));
|
renderer = std::unique_ptr<IRenderer>(PlatformProducer::CreateRenderManager(renderApi));
|
||||||
app->SetGraphicsAppManager(this);
|
inputManager = Input::InputManager::GetInstance();
|
||||||
window->SetWindowHandler(this);
|
engineConfig = EngineConfiguration::GetEngineConfiguration();
|
||||||
inputManager = OpenVulkano::Input::InputManager::GetInstance();
|
|
||||||
engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
|
||||||
engineConfig->OnFpsCapChanged += EventHandler(this, &GraphicsAppManager::UpdateCappedFpsInfo);
|
engineConfig->OnFpsCapChanged += EventHandler(this, &GraphicsAppManager::UpdateCappedFpsInfo);
|
||||||
|
if (window)
|
||||||
|
{
|
||||||
|
this->window = window;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->window = platform->MakeWindow();
|
||||||
|
}
|
||||||
|
if (app)
|
||||||
|
{
|
||||||
|
app->SetGraphicsAppManager(this);
|
||||||
|
}
|
||||||
|
this->window->SetWindowHandler(this);
|
||||||
|
|
||||||
// set initial values
|
// set initial values
|
||||||
if (engineConfig->GetFpsCap() > 0)
|
if (engineConfig->GetFpsCap() > 0)
|
||||||
{
|
{
|
||||||
UpdateCappedFpsInfo(engineConfig->GetFpsCap());
|
UpdateCappedFpsInfo(engineConfig->GetFpsCap());
|
||||||
}
|
}
|
||||||
|
if (platform)
|
||||||
|
{
|
||||||
|
platform->Init();
|
||||||
|
}
|
||||||
|
Logger::MANAGER->info("Initialized...");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsAppManager::UpdateCappedFpsInfo(int32_t newFpsCap)
|
void GraphicsAppManager::UpdateCappedFpsInfo(int32_t newFpsCap)
|
||||||
@@ -144,6 +143,12 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
void GraphicsAppManager::StartUp()
|
void GraphicsAppManager::StartUp()
|
||||||
{
|
{
|
||||||
|
if (!app)
|
||||||
|
{
|
||||||
|
constexpr auto msg = "The app must not be null!";
|
||||||
|
Logger::MANAGER->error(msg);
|
||||||
|
throw std::runtime_error(msg);
|
||||||
|
}
|
||||||
#ifdef HAS_TRACY
|
#ifdef HAS_TRACY
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
#endif
|
#endif
|
||||||
@@ -151,7 +156,9 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
Logger::MANAGER->info("Initializing ...");
|
Logger::MANAGER->info("Initializing ...");
|
||||||
app->Init();
|
app->Init();
|
||||||
if (platform) platform->Init();
|
|
||||||
|
//if (platform) platform->Init();
|
||||||
|
|
||||||
window->Init(renderApi);
|
window->Init(renderApi);
|
||||||
//TODO restore window settings if there are any set
|
//TODO restore window settings if there are any set
|
||||||
renderer->Init(static_cast<IGraphicsAppManager*>(this), window);
|
renderer->Init(static_cast<IGraphicsAppManager*>(this), window);
|
||||||
|
|||||||
@@ -48,10 +48,17 @@ namespace OpenVulkano
|
|||||||
void OnCappedFPS(const auto& frameStartTime);
|
void OnCappedFPS(const auto& frameStartTime);
|
||||||
void UpdateCappedFpsInfo(int32_t newFpsCap);
|
void UpdateCappedFpsInfo(int32_t newFpsCap);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
GraphicsAppManager(RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||||
|
|
||||||
explicit GraphicsAppManager(IGraphicsApp* app, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
explicit GraphicsAppManager(IGraphicsApp* app, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||||
|
|
||||||
explicit GraphicsAppManager(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
explicit GraphicsAppManager(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||||
|
|
||||||
|
void SetApp(IGraphicsApp* app);
|
||||||
|
|
||||||
|
void Init(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi);
|
||||||
|
|
||||||
~GraphicsAppManager() noexcept override;
|
~GraphicsAppManager() noexcept override;
|
||||||
|
|
||||||
public: // Getter
|
public: // Getter
|
||||||
|
|||||||
Reference in New Issue
Block a user