texture asset

This commit is contained in:
2018-11-28 15:48:56 +07:00
parent a4b6b4f6a0
commit 27c7ce57d5
3 changed files with 30 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ namespace e2d
class text_asset;
class image_asset;
class binary_asset;
class texture_asset;
template < typename T >
class asset_cache;

View File

@@ -41,4 +41,10 @@ namespace e2d
using content_asset<buffer>::content_asset;
static std::shared_ptr<binary_asset> load(library& library, str_view address);
};
class texture_asset final : public content_asset<texture_ptr> {
public:
using content_asset<texture_ptr>::content_asset;
static std::shared_ptr<texture_asset> load(library& library, str_view address);
};
}

View File

@@ -46,13 +46,13 @@ namespace e2d
std::shared_ptr<image_asset> image_asset::load(library& library, str_view address) {
const auto image_data = library.load_asset<binary_asset>(address);
if ( !image_data) {
if ( !image_data ) {
return nullptr;
}
image content;
if ( !images::try_load_image(content, image_data->content()) ) {
the<debug>().error("ASSETS: Failed to load image asset:\n"
the<debug>().error("ASSETS: Failed to create image asset:\n"
"--> Address: %0",
address);
return nullptr;
@@ -87,4 +87,25 @@ namespace e2d
return std::make_shared<binary_asset>(std::move(content));
}
//
// texture_asset
//
std::shared_ptr<texture_asset> texture_asset::load(library& library, str_view address) {
const auto texture_data = library.load_asset<image_asset>(address);
if ( !texture_data ) {
return nullptr;
}
const auto content = the<render>().create_texture(texture_data->content());
if ( !content ) {
the<debug>().error("ASSETS: Failed to create texture asset:\n"
"--> Address: %0",
address);
return nullptr;
}
return std::make_shared<texture_asset>(content);
}
}