recrownedgtk/RecrownedGTK/Graphics/VertexBufferHandle.cs

37 lines
1.1 KiB
C#

using System;
using OpenTK.Graphics.OpenGL;
namespace RecrownedGTK.Graphics {
public class VertexBufferHandle : IDisposable {
private bool disposed;
private int handle;
public VertexBufferHandle() {
handle = GL.GenBuffer();
}
public void Bind() {
GL.BindBuffer(BufferTarget.ArrayBuffer, handle);
}
public void Unbind() {
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
}
public void Flush(float[] vertices, BufferUsageHint hint = BufferUsageHint.StaticDraw) {
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, hint);
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposed) return;
if (disposing) {
}
Unbind();
GL.DeleteBuffer(handle);
disposed = true;
}
~VertexBufferHandle() {
Dispose(false);
}
}
}