Nerfed/Nerfed.Runtime/Gui/TextureStorage.cs
max 1e1ed303ad Added ImGui.NET
Start working on controller.
2024-07-05 21:56:14 +02:00

35 lines
872 B
C#

using Nerfed.Runtime.Graphics;
namespace Nerfed.Runtime.Gui;
public class TextureStorage
{
private readonly Dictionary<IntPtr, WeakReference<Texture>> pointerToTexture = new Dictionary<IntPtr, WeakReference<Texture>>();
public IntPtr Add(Texture texture)
{
if (!pointerToTexture.ContainsKey(texture.Handle))
{
pointerToTexture.Add(texture.Handle, new WeakReference<Texture>(texture));
}
return texture.Handle;
}
public Texture GetTexture(IntPtr pointer)
{
if (!pointerToTexture.ContainsKey(pointer))
{
return null;
}
WeakReference<Texture> result = pointerToTexture[pointer];
if (!result.TryGetTarget(out Texture texture))
{
pointerToTexture.Remove(pointer);
return null;
}
return texture;
}
}