From 687574bf8397cfd9b306e30b07d129fd7f4cab2f Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 21 Aug 2019 09:21:29 +0700 Subject: [PATCH] font atlas as nested asset of font_asset --- sources/enduro2d/high/assets/font_asset.cpp | 28 ++++++++++++++++++- .../enduro2d/high/systems/label_system.cpp | 13 +++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/sources/enduro2d/high/assets/font_asset.cpp b/sources/enduro2d/high/assets/font_asset.cpp index 603a2c6a..79e07cf4 100644 --- a/sources/enduro2d/high/assets/font_asset.cpp +++ b/sources/enduro2d/high/assets/font_asset.cpp @@ -5,7 +5,9 @@ ******************************************************************************/ #include + #include +#include namespace { @@ -30,8 +32,32 @@ namespace e2d if ( !fonts::try_load_font(content, font_data->content()) ) { throw font_asset_loading_exception(); } - return font_asset::create(std::move(content)); + return content; }); + }) + .then([ + &library, + parent_address = path::parent_path(address) + ](const font& content){ + return stdex::make_tuple_promise(std::make_tuple( + stdex::make_resolved_promise(content), + library.load_asset_async( + path::combine(parent_address, content.info().atlas_file)) + )); + }) + .then([](const std::tuple< + font, + texture_asset::load_result + >& results){ + font content = std::get<0>(results); + texture_asset::load_result texture_res = std::get<1>(results); + if ( content.info().atlas_size != texture_res->content()->size() ) { + throw font_asset_loading_exception(); + } + nested_content ncontent{{ + make_hash(content.info().atlas_file), + std::move(texture_res)}}; + return font_asset::create(std::move(content), std::move(ncontent)); }); } } diff --git a/sources/enduro2d/high/systems/label_system.cpp b/sources/enduro2d/high/systems/label_system.cpp index 8278fb5b..2aae797e 100644 --- a/sources/enduro2d/high/systems/label_system.cpp +++ b/sources/enduro2d/high/systems/label_system.cpp @@ -167,12 +167,13 @@ namespace using namespace e2d; void update_label_material(const label& l, renderer& r) { - if ( r.materials().empty() ) { - return; - } + auto texture_res = l.font() && !l.font()->content().empty() + ? l.font()->find_nested_asset(l.font()->content().info().atlas_file) + : nullptr; - auto texture_p = the().load_asset( - l.font()->content().info().atlas_file); + auto texture = texture_res + ? texture_res->content() + : nullptr; const f32 glyph_dilate = math::clamp(l.glyph_dilate(), -1.f, 1.0f); const f32 outline_width = math::clamp(l.outline_width(), 0.f, 1.f - glyph_dilate); @@ -180,7 +181,7 @@ namespace r.properties(render::property_block() .sampler("u_texture", render::sampler_state() - .texture(texture_p->content()) + .texture(texture) .min_filter(render::sampler_min_filter::linear) .mag_filter(render::sampler_mag_filter::linear)) .property("u_glyph_dilate", glyph_dilate)