2020-02-17 02:44:21 +00:00
|
|
|
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() {
|
2020-02-17 07:27:14 +00:00
|
|
|
|
2020-02-17 02:44:21 +00:00
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
|
|
}
|
2020-02-17 07:27:14 +00:00
|
|
|
public void Flush(float[] vertices, BufferUsageHint hint = BufferUsageHint.StaticDraw) {
|
|
|
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, hint);
|
2020-02-17 02:44:21 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|