chore(asset_manager): delete unused module
This commit is contained in:
parent
83a872f3f3
commit
85dbe47990
3 changed files with 0 additions and 179 deletions
|
@ -1,9 +0,0 @@
|
|||
add_library_module(asset_manager
|
||||
asset_manager.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
asset_manager
|
||||
PUBLIC asset_parser
|
||||
PRIVATE logger
|
||||
)
|
|
@ -1,92 +0,0 @@
|
|||
#include <asset_manager/asset_manager.hpp>
|
||||
#include <asset_parser/assets/text.hpp>
|
||||
#include <asset_parser/assets/texture.hpp>
|
||||
#include <logger/logger.hpp>
|
||||
#include <renderer/graphics_context.hpp>
|
||||
#include <renderer/shader.hpp>
|
||||
#include <renderer/texture.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
/* static */ auto AssetManager::instance() -> AssetManager &
|
||||
{
|
||||
static auto instance = AssetManager {};
|
||||
return instance;
|
||||
}
|
||||
|
||||
void AssetManager::load_shader_impl(
|
||||
const std::string &name,
|
||||
const std::filesystem::path &vertex_path,
|
||||
const std::filesystem::path &pixel_path
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
log_trc("Loading shader:");
|
||||
log_trc("\tname : {}", name);
|
||||
log_trc("\tvertex path: {}", vertex_path.string());
|
||||
log_trc("\tpixel path : {}", pixel_path.string());
|
||||
|
||||
m_shaders[name] = Ref<Shader>(Shader::create(
|
||||
get_or_load_text_asset(vertex_path.string()),
|
||||
get_or_load_text_asset(pixel_path),
|
||||
GraphicsContext::get_shared_context()
|
||||
));
|
||||
}
|
||||
catch (const std::exception &exp)
|
||||
{
|
||||
log_err("Failed to load shader:");
|
||||
log_err("\tname : {}", name);
|
||||
log_err("\tvertex path: {}", vertex_path.string());
|
||||
log_err("\tpixel path : {}", pixel_path.string());
|
||||
log_err("\texception : {}", exp.what());
|
||||
}
|
||||
}
|
||||
|
||||
void AssetManager::load_texture_impl(const std::string &name, const std::filesystem::path &path)
|
||||
{
|
||||
try
|
||||
{
|
||||
log_trc("Loading texture:");
|
||||
log_trc("\tname: {}", name);
|
||||
log_trc("\tpath: {}", path.string());
|
||||
|
||||
m_textures[name] = Ref<Texture>(
|
||||
Texture::create(get_or_load_texture_asset(path), GraphicsContext::get_shared_context())
|
||||
);
|
||||
}
|
||||
catch (const std::exception &exp)
|
||||
{
|
||||
log_err("Failed to load texture:");
|
||||
log_err("\tname : {}", name);
|
||||
log_err("\tpath : {}", path.string());
|
||||
log_err("\texception: {}", exp.what());
|
||||
}
|
||||
}
|
||||
|
||||
auto AssetManager::get_or_load_text_asset(const std::filesystem::path &path)
|
||||
-> Ref<Assets::TextAsset>
|
||||
{
|
||||
const auto key = std::filesystem::canonical(path).string();
|
||||
if (!m_text_assets.contains(key))
|
||||
{
|
||||
m_text_assets.emplace(key, create_ref<Assets::TextAsset>(path));
|
||||
}
|
||||
|
||||
return m_text_assets[key];
|
||||
}
|
||||
|
||||
auto AssetManager::get_or_load_texture_asset(const std::filesystem::path &path)
|
||||
-> Ref<Assets::TextureAsset>
|
||||
{
|
||||
const auto key = std::filesystem::canonical(path).string();
|
||||
if (!m_texture_assets.contains(key))
|
||||
{
|
||||
m_texture_assets.emplace(key, create_ref<Assets::TextureAsset>(path));
|
||||
}
|
||||
|
||||
return m_texture_assets[key];
|
||||
}
|
||||
|
||||
|
||||
} // namespace lt
|
|
@ -1,78 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace Assets {
|
||||
|
||||
class TextAsset;
|
||||
|
||||
class TextureAsset;
|
||||
|
||||
} // namespace Assets
|
||||
|
||||
namespace lt {
|
||||
|
||||
class Shader;
|
||||
class Texture;
|
||||
|
||||
/**
|
||||
* Asset is the data on the disk.
|
||||
* Resource is the data on the gpu/cpu
|
||||
*
|
||||
* eg. TextureAsset is the file on the disk
|
||||
* eg. Texture is the representation of it in the GPU
|
||||
*/
|
||||
class AssetManager
|
||||
{
|
||||
public:
|
||||
static void load_shader(
|
||||
const std::string &name,
|
||||
const std::filesystem::path &vertex_path,
|
||||
const std::filesystem::path &pixel_path
|
||||
)
|
||||
{
|
||||
instance().load_shader_impl(name, vertex_path, pixel_path);
|
||||
}
|
||||
|
||||
static void load_texture(const std::string &name, const std::filesystem::path &path)
|
||||
{
|
||||
instance().load_texture_impl(name, path);
|
||||
}
|
||||
|
||||
static auto get_shader(const std::string &name) -> Ref<Shader>
|
||||
{
|
||||
return instance().m_shaders[name];
|
||||
}
|
||||
|
||||
static auto get_texture(const std::string &name) -> Ref<Texture>
|
||||
{
|
||||
return instance().m_textures[name];
|
||||
}
|
||||
|
||||
private:
|
||||
AssetManager() = default;
|
||||
|
||||
static auto instance() -> AssetManager &;
|
||||
|
||||
void load_shader_impl(
|
||||
const std::string &name,
|
||||
const std::filesystem::path &vertex_path,
|
||||
const std::filesystem::path &pixel_path
|
||||
);
|
||||
|
||||
void load_texture_impl(const std::string &name, const std::filesystem::path &path);
|
||||
|
||||
auto get_or_load_text_asset(const std::filesystem::path &path) -> Ref<Assets::TextAsset>;
|
||||
|
||||
auto get_or_load_texture_asset(const std::filesystem::path &path) -> Ref<Assets::TextureAsset>;
|
||||
|
||||
std::unordered_map<std::string, Ref<Assets::TextAsset>> m_text_assets;
|
||||
|
||||
std::unordered_map<std::string, Ref<Assets::TextureAsset>> m_texture_assets;
|
||||
|
||||
std::unordered_map<std::string, Ref<Shader>> m_shaders;
|
||||
|
||||
std::unordered_map<std::string, Ref<Texture>> m_textures;
|
||||
};
|
||||
|
||||
} // namespace lt
|
Loading…
Add table
Reference in a new issue