GLObject implements IDisposable

This commit is contained in:
2017-02-26 00:33:29 -05:00
parent b30f79acda
commit ce3b5cce6c
6 changed files with 102 additions and 50 deletions

View File

@@ -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;
}