Route startup resources through app core
This commit is contained in:
21
src/app.cpp
21
src/app.cpp
@@ -143,11 +143,6 @@ void apply_app_scissor_test(bool enabled)
|
||||
LOG("OpenGL scissor test failed: %s", status.message);
|
||||
}
|
||||
|
||||
[[nodiscard]] GLint rgba8_internal_format() noexcept
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba8_internal_format());
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum linear_texture_filter() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::linear_texture_filter());
|
||||
@@ -450,12 +445,16 @@ void App::init()
|
||||
LOG("App startup persistence failed: %s", persistence_status.message);
|
||||
}
|
||||
|
||||
initShaders();
|
||||
initAssets();
|
||||
initLayout();
|
||||
title_update();
|
||||
|
||||
uirtt.create(width, height, -1, rgba8_internal_format(), true);
|
||||
const auto startup_resources = pp::app::plan_app_startup_resources(width, height);
|
||||
if (!startup_resources) {
|
||||
LOG("App startup resource plan failed: %s", startup_resources.status().message);
|
||||
} else {
|
||||
const auto resource_status = pp::panopainter::execute_legacy_app_startup_resources(
|
||||
*this,
|
||||
startup_resources.value());
|
||||
if (!resource_status.ok())
|
||||
LOG("App startup resources failed: %s", resource_status.message);
|
||||
}
|
||||
|
||||
if (startup_plan) {
|
||||
const auto startup_status = pp::panopainter::execute_legacy_app_startup_runtime_plan(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
namespace pp::app {
|
||||
@@ -15,6 +16,16 @@ struct AppStartupPlan {
|
||||
bool show_license_warning = false;
|
||||
};
|
||||
|
||||
struct AppStartupResourcePlan {
|
||||
int ui_render_target_width = 0;
|
||||
int ui_render_target_height = 0;
|
||||
bool initialize_shaders = true;
|
||||
bool initialize_assets = true;
|
||||
bool initialize_layout = true;
|
||||
bool update_title = true;
|
||||
bool create_ui_render_target = true;
|
||||
};
|
||||
|
||||
class AppStartupServices {
|
||||
public:
|
||||
virtual ~AppStartupServices() = default;
|
||||
@@ -26,6 +37,17 @@ public:
|
||||
virtual void show_license_warning() = 0;
|
||||
};
|
||||
|
||||
class AppStartupResourceServices {
|
||||
public:
|
||||
virtual ~AppStartupResourceServices() = default;
|
||||
|
||||
virtual void initialize_shaders() = 0;
|
||||
virtual void initialize_assets() = 0;
|
||||
virtual void initialize_layout() = 0;
|
||||
virtual void update_title() = 0;
|
||||
virtual void create_ui_render_target(int width, int height) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<AppStartupPlan> plan_app_startup(
|
||||
int current_run_counter,
|
||||
bool auto_timelapse_enabled,
|
||||
@@ -51,6 +73,32 @@ public:
|
||||
return pp::foundation::Result<AppStartupPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<AppStartupResourcePlan> plan_app_startup_resources(
|
||||
float ui_width,
|
||||
float ui_height)
|
||||
{
|
||||
if (!std::isfinite(ui_width) || !std::isfinite(ui_height)) {
|
||||
return pp::foundation::Result<AppStartupResourcePlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("startup resource dimensions must be finite"));
|
||||
}
|
||||
|
||||
if (ui_width < 1.0F || ui_height < 1.0F) {
|
||||
return pp::foundation::Result<AppStartupResourcePlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("startup resource dimensions must be positive"));
|
||||
}
|
||||
|
||||
if (ui_width > static_cast<float>(std::numeric_limits<int>::max())
|
||||
|| ui_height > static_cast<float>(std::numeric_limits<int>::max())) {
|
||||
return pp::foundation::Result<AppStartupResourcePlan>::failure(
|
||||
pp::foundation::Status::out_of_range("startup resource dimensions exceed integer range"));
|
||||
}
|
||||
|
||||
AppStartupResourcePlan plan;
|
||||
plan.ui_render_target_width = static_cast<int>(ui_width);
|
||||
plan.ui_render_target_height = static_cast<int>(ui_height);
|
||||
return pp::foundation::Result<AppStartupResourcePlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_app_startup_plan(
|
||||
const AppStartupPlan& plan,
|
||||
AppStartupServices& services)
|
||||
@@ -109,4 +157,32 @@ public:
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_app_startup_resources(
|
||||
const AppStartupResourcePlan& plan,
|
||||
AppStartupResourceServices& services)
|
||||
{
|
||||
if (plan.create_ui_render_target
|
||||
&& (plan.ui_render_target_width <= 0 || plan.ui_render_target_height <= 0)) {
|
||||
return pp::foundation::Status::invalid_argument("startup resource plan has invalid UI render target size");
|
||||
}
|
||||
|
||||
if (plan.initialize_shaders) {
|
||||
services.initialize_shaders();
|
||||
}
|
||||
if (plan.initialize_assets) {
|
||||
services.initialize_assets();
|
||||
}
|
||||
if (plan.initialize_layout) {
|
||||
services.initialize_layout();
|
||||
}
|
||||
if (plan.update_title) {
|
||||
services.update_title();
|
||||
}
|
||||
if (plan.create_ui_render_target) {
|
||||
services.create_ui_render_target(plan.ui_render_target_width, plan.ui_render_target_height);
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
} // namespace pp::app
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
#include "legacy_app_startup_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "serializer.h"
|
||||
#include "settings.h"
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
class LegacyAppStartupServices final : public pp::app::AppStartupServices {
|
||||
class LegacyAppStartupServices final
|
||||
: public pp::app::AppStartupServices
|
||||
, public pp::app::AppStartupResourceServices {
|
||||
public:
|
||||
explicit LegacyAppStartupServices(App& app) noexcept
|
||||
: app_(app)
|
||||
@@ -43,6 +46,36 @@ public:
|
||||
app_.message_box("License", "Could not validate this license, running in demo mode.");
|
||||
}
|
||||
|
||||
void initialize_shaders() override
|
||||
{
|
||||
app_.initShaders();
|
||||
}
|
||||
|
||||
void initialize_assets() override
|
||||
{
|
||||
app_.initAssets();
|
||||
}
|
||||
|
||||
void initialize_layout() override
|
||||
{
|
||||
app_.initLayout();
|
||||
}
|
||||
|
||||
void update_title() override
|
||||
{
|
||||
app_.title_update();
|
||||
}
|
||||
|
||||
void create_ui_render_target(int width, int height) override
|
||||
{
|
||||
app_.uirtt.create(
|
||||
width,
|
||||
height,
|
||||
-1,
|
||||
static_cast<GLint>(pp::renderer::gl::rgba8_internal_format()),
|
||||
true);
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
@@ -73,4 +106,12 @@ pp::foundation::Status execute_legacy_app_startup_runtime_plan(
|
||||
return pp::app::execute_app_startup_runtime_plan(plan, services);
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_app_startup_resources(
|
||||
App& app,
|
||||
const pp::app::AppStartupResourcePlan& plan)
|
||||
{
|
||||
LegacyAppStartupServices services(app);
|
||||
return pp::app::execute_app_startup_resources(plan, services);
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
|
||||
@@ -15,5 +15,8 @@ namespace pp::panopainter {
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_app_startup_runtime_plan(
|
||||
App& app,
|
||||
const pp::app::AppStartupPlan& plan);
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_app_startup_resources(
|
||||
App& app,
|
||||
const pp::app::AppStartupResourcePlan& plan);
|
||||
|
||||
} // namespace pp::panopainter
|
||||
|
||||
Reference in New Issue
Block a user