2023-12-15 18:46:43 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace MoonWorks.Graphics;
|
|
|
|
|
2024-06-05 19:34:24 +00:00
|
|
|
public abstract class RefreshResource : GraphicsResource
|
2023-12-15 18:46:43 +00:00
|
|
|
{
|
|
|
|
public IntPtr Handle { get => handle; internal set => handle = value; }
|
|
|
|
private IntPtr handle;
|
|
|
|
|
2024-06-04 19:19:41 +00:00
|
|
|
protected abstract Action<IntPtr, IntPtr> ReleaseFunction { get; }
|
2023-12-15 18:46:43 +00:00
|
|
|
|
2024-06-05 19:34:24 +00:00
|
|
|
protected RefreshResource(GraphicsDevice device) : base(device)
|
2023-12-15 18:46:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
if (!IsDisposed)
|
|
|
|
{
|
2024-06-04 19:19:41 +00:00
|
|
|
// Atomically call release function in case this is called from the finalizer thread
|
2023-12-15 18:46:43 +00:00
|
|
|
var toDispose = Interlocked.Exchange(ref handle, IntPtr.Zero);
|
|
|
|
if (toDispose != IntPtr.Zero)
|
|
|
|
{
|
2024-06-04 19:19:41 +00:00
|
|
|
ReleaseFunction(Device.Handle, toDispose);
|
2023-12-15 18:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
|
|
}
|
|
|
|
}
|