light/modules/asset_manager/public/asset_manager.hpp

79 lines
1.7 KiB
C++
Raw Permalink Normal View History

2025-07-05 13:28:41 +03:30
#pragma once
#include <filesystem>
2025-07-05 13:28:41 +03:30
2025-07-10 21:51:17 +03:30
namespace Assets {
class TextAsset;
class TextureAsset;
} // namespace Assets
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-05 13:28:41 +03:30
class Shader;
class Texture;
2025-07-10 21:51:17 +03:30
/**
* 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
2025-07-05 13:28:41 +03:30
{
public:
2025-07-06 14:02:50 +03:30
static void load_shader(
2025-07-05 13:28:41 +03:30
const std::string &name,
const std::filesystem::path &vertex_path,
const std::filesystem::path &pixel_path
2025-07-05 13:28:41 +03:30
)
{
instance().load_shader_impl(name, vertex_path, pixel_path);
2025-07-05 13:28:41 +03:30
}
static void load_texture(const std::string &name, const std::filesystem::path &path)
2025-07-05 13:28:41 +03:30
{
instance().load_texture_impl(name, path);
2025-07-05 13:28:41 +03:30
}
2025-07-06 14:02:50 +03:30
static auto get_shader(const std::string &name) -> Ref<Shader>
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
return instance().m_shaders[name];
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
2025-07-06 14:02:50 +03:30
static auto get_texture(const std::string &name) -> Ref<Texture>
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
return instance().m_textures[name];
2025-07-05 13:28:41 +03:30
}
private:
AssetManager() = default;
2025-07-05 13:28:41 +03:30
2025-07-10 21:51:17 +03:30
static auto instance() -> AssetManager &;
void load_shader_impl(
2025-07-05 13:28:41 +03:30
const std::string &name,
const std::filesystem::path &vertex_path,
const std::filesystem::path &pixel_path
2025-07-05 13:28:41 +03:30
);
void load_texture_impl(const std::string &name, const std::filesystem::path &path);
2025-07-05 13:28:41 +03:30
2025-07-10 21:51:17 +03:30
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;
2025-07-06 17:23:28 +03:30
std::unordered_map<std::string, Ref<Shader>> m_shaders;
std::unordered_map<std::string, Ref<Texture>> m_textures;
2025-07-05 13:28:41 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt