mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
font atlas as nested asset of font_asset
This commit is contained in:
@@ -5,7 +5,9 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <enduro2d/high/assets/font_asset.hpp>
|
#include <enduro2d/high/assets/font_asset.hpp>
|
||||||
|
|
||||||
#include <enduro2d/high/assets/binary_asset.hpp>
|
#include <enduro2d/high/assets/binary_asset.hpp>
|
||||||
|
#include <enduro2d/high/assets/texture_asset.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -30,8 +32,32 @@ namespace e2d
|
|||||||
if ( !fonts::try_load_font(content, font_data->content()) ) {
|
if ( !fonts::try_load_font(content, font_data->content()) ) {
|
||||||
throw font_asset_loading_exception();
|
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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,12 +167,13 @@ namespace
|
|||||||
using namespace e2d;
|
using namespace e2d;
|
||||||
|
|
||||||
void update_label_material(const label& l, renderer& r) {
|
void update_label_material(const label& l, renderer& r) {
|
||||||
if ( r.materials().empty() ) {
|
auto texture_res = l.font() && !l.font()->content().empty()
|
||||||
return;
|
? l.font()->find_nested_asset<texture_asset>(l.font()->content().info().atlas_file)
|
||||||
}
|
: nullptr;
|
||||||
|
|
||||||
auto texture_p = the<library>().load_asset<texture_asset>(
|
auto texture = texture_res
|
||||||
l.font()->content().info().atlas_file);
|
? texture_res->content()
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
const f32 glyph_dilate = math::clamp(l.glyph_dilate(), -1.f, 1.0f);
|
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);
|
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()
|
r.properties(render::property_block()
|
||||||
.sampler("u_texture", render::sampler_state()
|
.sampler("u_texture", render::sampler_state()
|
||||||
.texture(texture_p->content())
|
.texture(texture)
|
||||||
.min_filter(render::sampler_min_filter::linear)
|
.min_filter(render::sampler_min_filter::linear)
|
||||||
.mag_filter(render::sampler_mag_filter::linear))
|
.mag_filter(render::sampler_mag_filter::linear))
|
||||||
.property("u_glyph_dilate", glyph_dilate)
|
.property("u_glyph_dilate", glyph_dilate)
|
||||||
|
|||||||
Reference in New Issue
Block a user