font atlas as nested asset of font_asset

This commit is contained in:
2019-08-21 09:21:29 +07:00
parent c29c1643f0
commit 687574bf83
2 changed files with 34 additions and 7 deletions

View File

@@ -5,7 +5,9 @@
******************************************************************************/
#include <enduro2d/high/assets/font_asset.hpp>
#include <enduro2d/high/assets/binary_asset.hpp>
#include <enduro2d/high/assets/texture_asset.hpp>
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<texture_asset>(
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));
});
}
}

View File

@@ -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<texture_asset>(l.font()->content().info().atlas_file)
: nullptr;
auto texture_p = the<library>().load_asset<texture_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)