2025-07-05 13:28:41 +03:30
|
|
|
#pragma once
|
|
|
|
|
2025-07-09 15:30:54 +03:30
|
|
|
#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
|
|
|
|
*/
|
2025-07-10 13:29:03 +03:30
|
|
|
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,
|
2025-07-09 21:30:17 +03:30
|
|
|
const std::filesystem::path &vertex_path,
|
|
|
|
const std::filesystem::path &pixel_path
|
2025-07-05 13:28:41 +03:30
|
|
|
)
|
|
|
|
{
|
2025-07-09 21:30:17 +03:30
|
|
|
instance().load_shader_impl(name, vertex_path, pixel_path);
|
2025-07-05 13:28:41 +03:30
|
|
|
}
|
|
|
|
|
2025-07-09 21:30:17 +03:30
|
|
|
static void load_texture(const std::string &name, const std::filesystem::path &path)
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-09 15:30:54 +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:
|
2025-07-10 13:29:03 +03:30
|
|
|
AssetManager() = default;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-10 21:51:17 +03:30
|
|
|
static auto instance() -> AssetManager &;
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void load_shader_impl(
|
2025-07-05 13:28:41 +03:30
|
|
|
const std::string &name,
|
2025-07-09 21:30:17 +03:30
|
|
|
const std::filesystem::path &vertex_path,
|
|
|
|
const std::filesystem::path &pixel_path
|
2025-07-05 13:28:41 +03:30
|
|
|
);
|
|
|
|
|
2025-07-09 15:30:54 +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
|