diff --git a/include/luma/application.hpp b/include/luma/application.hpp index cc5b31e..bf61850 100644 --- a/include/luma/application.hpp +++ b/include/luma/application.hpp @@ -56,6 +56,7 @@ public: auto set_window_bounds(std::uint64_t id, luma::rect bounds) -> std::expected; auto set_window_visible(std::uint64_t id, std::bool_t visible) -> std::expected; auto load_texture(std::string path) -> std::expected, modulus::error>; + auto load_texture_uncached(std::string path) -> std::expected, modulus::error>; auto request_layout() -> std::expected; auto set_root(std::expected, modulus::error> root) -> std::expected; auto set_root(std::unique_ptr root) -> std::expected; diff --git a/src/application.cpp b/src/application.cpp index 9494a4b..efb72e2 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -985,6 +985,18 @@ auto luma::application::load_texture(std::string path) -> std::expectedassets->texture(path); }, false); } +auto luma::application::load_texture_uncached(std::string path) -> std::expected, modulus::error> { + if (path.empty()) { + return luma::detail::fail>(luma::detail::error_invalid_argument, "texture path must not be empty"); + } + auto core = core_snapshot(); + return dispatch_to_ui>(core, [core, path = std::move(path)] { + if (!core->renderer_active.load(std::memory_order_acquire) || !core->resources) { + return unavailable>("texture loading requires an active renderer"); + } + return core->resources->load_texture(path); }, false); +} + auto luma::application::request_layout() -> std::expected { auto core = core_snapshot(); return dispatch_to_ui(core, [core] { diff --git a/tests/test.cpp b/tests/test.cpp index cf7a6dd..82615b6 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -919,6 +919,12 @@ BOOST_AUTO_TEST_CASE(application_rejects_texture_load_without_renderer) { auto texture = app.load_texture("missing.png"); BOOST_REQUIRE(!texture); BOOST_TEST(texture.error().code() == 3); + auto uncached = app.load_texture_uncached("missing.png"); + BOOST_REQUIRE(!uncached); + BOOST_TEST(uncached.error().code() == 3); + auto empty = app.load_texture_uncached(""); + BOOST_REQUIRE(!empty); + BOOST_TEST(empty.error().code() == 1); } BOOST_AUTO_TEST_CASE(application_show_toast_requires_root) {