15 #include <unordered_map> 17 #include <emilib/gl_lib_fwd.hpp> 21 class DelayedDirWatcher;
22 using DelayedDirWatcher_UP = std::unique_ptr<DelayedDirWatcher>;
24 using ImageData = std::unique_ptr<void, std::function<void(void*)>>;
34 using ImageLoader = std::function<ImageData(const char* path, int* width, int* height, int* comp, int req_comp)>;
38 ImageData load_image_rgba(
const ImageLoader& image_loader,
const char* path,
size_t* out_width,
size_t* out_height);
45 using Recorder = std::function<void(const std::string& name)>;
48 TextureMngr(
const std::string& gfx_dir, ImageLoader image_loader);
56 gl::Texture_SP get_retain(
const std::string& name,
const gl::TexParams& params);
57 gl::Texture_SP get_retain(
const std::string& name) {
return get_retain(name, default_params()); }
61 gl::Texture*
get(
const std::string& name) {
return get(name, default_params()); }
78 void finalize_eviction();
81 const Texture* store(Texture_UP&& tex);
89 return gl::TexParams::clamped_linear();
91 return gl::TexParams::clamped();
98 void print_memory_usage(
const char* prefix=
"")
const;
103 void stop_recording();
109 std::string abs_path;
110 gl::Texture_SP texture;
114 void reload(
const std::string& name);
115 TexInfo* prefetch_tex_info(
const std::string& name,
const gl::TexParams& params);
118 using FileMap = std::unordered_map<std::string, TexInfo>;
120 std::string _gfx_dir;
121 ImageLoader _image_loader;
122 DelayedDirWatcher_UP _dir_watcher;
124 bool _is_evicting =
false;
void prefetch_all(const std::string &sub_folder="")
Recursively prefetch all textures in gfx_dir/sub_folder.
void start_recording(Recorder recorder)
gl::Texture_SP prefetch_retain(const std::string &name, const gl::TexParams ¶ms)
While holding on to this shared_ptr handle, the texture won't get evicted.
Definition: gl_lib_fwd.hpp:151
TextureMngr(const std::string &gfx_dir, ImageLoader image_loader)
Look for textures relative to gfx_dir.
size_t memory_usage(unsigned *out_tex_count) const
Bytes.
Definition: gl_lib.hpp:48
void update()
Call frequently (once a frame) for hot-reloading of textures.
Definition: texture_mngr.hpp:42
gl::Texture * prefetch(const std::string &name, const gl::TexParams ¶ms)
Get a handle to a texture which will be loaded by finalize_eviction.
Definition: coroutine.hpp:18