VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
deviceCache.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 12.10.2025.
5//
6#include "deviceCache.h"
7
8namespace visutwin::canvas
9{
10 void DeviceCache::remove(const std::shared_ptr<GraphicsDevice>& device) {
11 auto it = _cache.find(device.get());
12 if (it != _cache.end()) {
13 // Get the cached resource
14 auto resource = it->second;
15
16 // Remove from cache
17 _cache.erase(it);
18 }
19 }
20
21 void DeviceCache::handleDeviceLost(GraphicsDevice* device)
22 {
23 auto it = _cache.find(device);
24 if (it != _cache.end()) {
25 // Get the cached resource
26 auto resource = it->second;
27
28 // Try to call loseContext method if the resource has one
29 // Note: Similar to destroy(), this requires the concrete type
30 // or a common interface. The JavaScript version uses optional
31 // chaining: resource?.loseContext?.(device)
32 //
33 // In a full C++ implementation, you would either:
34 // 1. Define an interface with loseContext() method
35 // 2. Use type traits to detect if the type has loseContext()
36 // 3. Let the resource handle device loss through the event system
37 }
38 }
39}
void remove(const std::shared_ptr< GraphicsDevice > &_graphicsDevice)
Abstract GPU interface for resource creation, state management, and draw submission.