Member Function Documentation

{
std::string key = Hash(texture_id, width, height);
BaseTexturePtr texture(cache_[key]);
if (!texture)
{
texture = slot(texture_id, width, height);
// Now here is the magic.//// The slot function is required to return a new texture. This has an// internal reference count of one. The TextureCache wants to hold the// texture inside the internal map for as long as the object itself// exists, but it doesn't want any ownership of the texture. How we// handle this is to always return a smart pointer for the texture. These// smart pointers have the ownership of the texture.//// We also hook into the objects OnDestroyed signal to remove it from the// map. To avoid a reverse lookup map, we bind the key to the method// call. By using a mem_fun rather than a lambda function, and through// the magic of sigc::trackable, we don't need to remember the connection// itself. We get notified when the object is being destroyed, and if we// are destroyed first, then the sigc::trackable disconnects all methods// created using mem_fun.// Reduce the internal reference count of the texture, so the smart// pointer is the sole owner of the object.
texture->UnReference();
cache_[key] = texture.GetPointer();
auto on_destroy = sigc::mem_fun(this, &TextureCache::OnDestroyNotify);
texture->OnDestroyed.connect(sigc::bind(on_destroy, key));
}
return texture;
}