Euphoria
texturecache.cc
Go to the documentation of this file.
1 #include "render/texturecache.h"
2 
3 #include "assert/assert.h"
4 #include "core/cache.h"
5 #include "io/vfs_path.h"
6 
7 #include "render/texture.h"
8 
9 namespace eu::render
10 {
12  : core::Cache<io::FilePath, Texture2, TextureCache::TextureCachePimpl>
13  {
14  explicit TextureCachePimpl(io::FileSystem* fs) : vfs(fs)
15  {
16  ASSERT(fs);
17  }
18 
19  [[nodiscard]] std::shared_ptr<Texture2>
20  create(const io::FilePath& file) const
21  {
22  auto ret = std::make_shared<Texture2>();
23  ret->load_from_file
24  (
25  vfs,
26  file,
29  );
30  return ret;
31  }
32 
34  };
35 
36 
38  {
39  pimpl = std::make_unique<TextureCache::TextureCachePimpl>(fs);
40  }
41 
42 
43  TextureCache::~TextureCache() = default;
44 
45 
46  std::shared_ptr<Texture2>
48  {
49  return pimpl->get(path);
50  }
51 
52 
53  std::shared_ptr<Texture2>
54  TextureCache::get_texture(const std::optional<io::FilePath>& path) const
55  {
56  if(path.has_value())
57  {
58  return get_texture(path.value());
59  }
60  else
61  {
62  return nullptr;
63  }
64  }
65 }
#define ASSERT(x)
Definition: assert.h:29
std::shared_ptr< Texture2 > create(const io::FilePath &file) const
Definition: texturecache.cc:20
std::unique_ptr< TextureCachePimpl > pimpl
Definition: texturecache.h:33
std::shared_ptr< Texture2 > get_texture(const io::FilePath &path) const
Definition: texturecache.cc:47
TextureCache(io::FileSystem *fs)
Definition: texturecache.cc:37