MOS
assets.hpp
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <unordered_map>
6 
7 #include <json.hpp>
8 
9 #include <mos/gfx/character.hpp>
10 #include <mos/gfx/environment_light.hpp>
11 #include <mos/gfx/font.hpp>
12 #include <mos/gfx/mesh.hpp>
13 #include <mos/gfx/model.hpp>
14 #include <mos/gfx/spot_light.hpp>
15 #include <mos/gfx/texture_2d.hpp>
16 
17 namespace mos::gfx {
18 
20 class Assets final {
21 public:
24  explicit Assets(std::string directory = "assets/");
25 
26  Assets(const Assets &assets) = delete;
27  Assets(const Assets &&assets) = delete;
28  Assets &operator=(const Assets &assets) = delete;
29  Assets &operator=(const Assets &&assets) = delete;
30  ~Assets() = default;
31 
33  auto mesh(const std::string &path) -> Shared_mesh;
34 
37  auto texture(const std::string &path, bool color_data = true,
38  bool mipmaps = true,
39  const Texture_2D::Filter &filter = Texture_2D::Filter::Linear,
40  const Texture_2D::Wrap &wrap = Texture_2D::Wrap::Repeat)
41  -> Shared_texture_2D;
42 
44  auto clear_unused() -> void;
45 
47  auto clear() -> void;
48 
50  auto directory() const -> std::string;
51 
52 private:
53  using Meshes = std::unordered_map<std::string, Shared_mesh>;
54  using Textures = std::unordered_map<std::string, Shared_texture_2D>;
55 
56  const std::string directory_;
57  Meshes meshes_;
58  Textures textures_;
59 };
60 } // namespace mos::gfx
Assets(std::string directory="assets/")
auto mesh(const std::string &path) -> Shared_mesh
Loads a Mesh from a *.mesh file and caches it internally.
Cache for faster loading of textures and meshes.
Definition: assets.hpp:20
Definition: assets.hpp:17
auto clear_unused() -> void
Remove all unused assets.
auto directory() const -> std::string
Parent directory of the cache.
auto texture(const std::string &path, bool color_data=true, bool mipmaps=true, const Texture_2D::Filter &filter=Texture_2D::Filter::Linear, const Texture_2D::Wrap &wrap=Texture_2D::Wrap::Repeat) -> Shared_texture_2D
Loads Texture2D from a *.png file or *.texture and caches it internally.
auto clear() -> void
Clear all assets.