recrownedgtk/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs

33 lines
1016 B
C#

using System;
using OpenTK.Graphics.OpenGL;
namespace RecrownedGTK.Graphics {
public class VertexBufferArrayHandle : IDisposable {
private bool disposed;
private int handle;
public VertexBufferArrayHandle() {
handle = GL.GenBuffer();
}
public void Bind() {
GL.BindBuffer(BufferTarget.ArrayBuffer, handle);
}
public void Buffer(float[] vertices, BufferUsageHint hint = BufferUsageHint.DynamicCopy) {
Bind();
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) {
}
GL.DeleteBuffer(handle);
disposed = true;
}
~VertexBufferArrayHandle() {
Dispose(false);
}
}
}