22 void remove(
const std::shared_ptr<GraphicsDevice>& _graphicsDevice);
25 std::shared_ptr<T>
get(
const std::shared_ptr<GraphicsDevice>& device,
26 std::function<std::shared_ptr<T>()> onCreate);
31 std::unordered_map<GraphicsDevice*, std::shared_ptr<void>> _cache;
35 std::shared_ptr<T>
DeviceCache::get(
const std::shared_ptr<GraphicsDevice>& device, std::function<std::shared_ptr<T>()> onCreate) {
36 auto it = _cache.find(device.get());
38 if (it == _cache.end()) {
40 auto resource = onCreate();
43 _cache[device.get()] = std::static_pointer_cast<void>(resource);
46 auto destroyCallback = [
this, device]() {
50 auto deviceLostCallback = [
this, device]() {
51 handleDeviceLost(device.get());
55 device->on(
"destroy", destroyCallback);
56 device->on(
"devicelost", deviceLostCallback);
62 return std::static_pointer_cast<T>(_cache[device.get()]);