From 289799a6afc4b15534665a6e380d306baba622ab Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 17 Feb 2020 02:31:15 -0500 Subject: [PATCH] Started work on the ElementBufferHandle. --- RecrownedGTK/Graphics/ElementBufferHandle.cs | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 RecrownedGTK/Graphics/ElementBufferHandle.cs diff --git a/RecrownedGTK/Graphics/ElementBufferHandle.cs b/RecrownedGTK/Graphics/ElementBufferHandle.cs new file mode 100644 index 0000000..e1410b0 --- /dev/null +++ b/RecrownedGTK/Graphics/ElementBufferHandle.cs @@ -0,0 +1,41 @@ +using System; +using OpenTK.Graphics.OpenGL; +namespace RecrownedGTK.Graphics { + public class ElementBufferHandle : IDisposable { + private bool disposed; + private int handle; + public ElementBufferHandle() { + handle = GL.GenBuffer(); + } + public void Bind() { + GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle); + } + + public void Unbind() { + GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); + } + + public void Flush(uint[] indices, BufferUsageHint hint = BufferUsageHint.StaticDraw) { + GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, hint); + } + + public void Dispose() { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) { + if (disposed) return; + if (disposing) { + + } + disposed = true; + Unbind(); + GL.DeleteBuffer(handle); + } + + ~ElementBufferHandle() { + Dispose(false); + } + } +} \ No newline at end of file