emilib
Classes | Public Types | Public Member Functions | List of all members
emilib::TextureMngr Class Reference

#include <texture_mngr.hpp>

Public Types

using Recorder = std::function< void(const std::string &name)>
 

Public Member Functions

 TextureMngr (const std::string &gfx_dir, ImageLoader image_loader)
 Look for textures relative to gfx_dir.
 
void update ()
 Call frequently (once a frame) for hot-reloading of textures.
 
gl::Texture_SP prefetch_retain (const std::string &name, const gl::TexParams &params)
 While holding on to this shared_ptr handle, the texture won't get evicted.
 
gl::Texture_SP get_retain (const std::string &name, const gl::TexParams &params)
 
gl::Texture_SP get_retain (const std::string &name)
 
gl::Textureget (const std::string &name, const gl::TexParams &params)
 Get a texture ready for use.
 
gl::Textureget (const std::string &name)
 
gl::Textureprefetch (const std::string &name, const gl::TexParams &params)
 Get a handle to a texture which will be loaded by finalize_eviction.
 
gl::Textureprefetch (const std::string &name)
 
void prefetch_all (const std::string &sub_folder="")
 Recursively prefetch all textures in gfx_dir/sub_folder.
 
void prepare_eviction ()
 
void finalize_eviction ()
 
const gl::Textureblack () const
 
const gl::Texturewhite () const
 
gl::TexParams default_params () const
 
size_t memory_usage (unsigned *out_tex_count) const
 Bytes.
 
void print_memory_usage (const char *prefix="") const
 
void start_recording (Recorder recorder)
 
void stop_recording ()
 

Detailed Description

Handles loading, unloading, memoization of textures. If a file changes on disk, that file is hot-reloaded by a call to update().

Member Function Documentation

◆ prepare_eviction()

void emilib::TextureMngr::prepare_eviction ( )

When we need to load a bunch of new things it is prudent to throw out the old. We do this in three steps: 1) call prepare_eviction 2) call prefetch (or get) on all textures you are planning to use 3) call finalize_eviction, which will, in order:

  • throw out all textures not marked in step 2.
  • load all textures prefetched in step 2

◆ start_recording()

void emilib::TextureMngr::start_recording ( Recorder  recorder)

Let's say you want to load a bunch of resources and later reload the same ones. You can use a Recorder to record all things being loaded.


The documentation for this class was generated from the following file: