GLObject implements IDisposable
This commit is contained in:
@@ -7,7 +7,7 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace hexworld.Util
|
||||
{
|
||||
public abstract class GLObject
|
||||
public abstract class GLObject : IDisposable
|
||||
{
|
||||
public uint Id { get; protected set; }
|
||||
|
||||
@@ -16,6 +16,22 @@ namespace hexworld.Util
|
||||
Id = id;
|
||||
}
|
||||
|
||||
protected abstract void Delete();
|
||||
|
||||
private bool _disposed = false;
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
Delete();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~GLObject()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public static explicit operator uint(GLObject o) => o.Id;
|
||||
public static explicit operator int(GLObject o) => (int) o.Id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user